Click here to Skip to main content
15,901,505 members
Home / Discussions / C#
   

C#

 
GeneralRe: question about Timer Tick event [modified] Pin
Mike Dimmick27-Aug-06 11:00
Mike Dimmick27-Aug-06 11:00 
GeneralRe: question about Timer Tick event Pin
likefood27-Aug-06 12:50
likefood27-Aug-06 12:50 
QuestionDateTime format Pin
kani9825-Aug-06 11:55
kani9825-Aug-06 11:55 
AnswerRe: DateTime format Pin
Ravi Bhavnani25-Aug-06 12:18
professionalRavi Bhavnani25-Aug-06 12:18 
AnswerRe: DateTime format Pin
drdavef25-Aug-06 12:29
drdavef25-Aug-06 12:29 
AnswerRe: DateTime format Pin
AnshShar25-Aug-06 12:43
AnshShar25-Aug-06 12:43 
AnswerRe: DateTime format Pin
Scott Dorman1-Sep-06 13:29
professionalScott Dorman1-Sep-06 13:29 
Questioncan someone help plz: threading the PingReply Pin
Jassim Rahma25-Aug-06 8:30
Jassim Rahma25-Aug-06 8:30 
I am getting this error when trying to use the Threading in PingReply:

Cross-thread operation not valid: Control 'lstHosts' accessed from a thread other than the thread it was created on.



THIS IS THE CODE:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Xml;

using System.Net;

using System.Net.NetworkInformation;

using System.Threading;

namespace HostHealth

{

public partial class frmMain : Form

{

private Thread ping_thread = null;

int listview_item;

public frmMain()

{

InitializeComponent();

}

private void ping_to_host()

{

for (listview_item = 0; listview_item <= lstHosts.Items.Count - 1; listview_item++)

{

Ping ping_sender = new Ping();

PingOptions ping_options = new PingOptions();

ping_options.DontFragment = true;

PingReply ping_reply = ping_sender.Send(lstHosts.Items[listview_item].SubItems[1].Text);

if (ping_reply.Status == IPStatus.Success)

{

lstHosts.Items[listview_item].SubItems[0].Text = "Success";

lstHosts.Items[listview_item].SubItems[2].Text = ping_reply.RoundtripTime.ToString();

lstHosts.Items[listview_item].SubItems[3].Text = ping_reply.Options.Ttl.ToString();

lstHosts.Items[listview_item].BackColor = Color.Black;

}

else

{

lstHosts.Items[listview_item].SubItems[0].Text = ping_reply.Status.ToString();

lstHosts.Items[listview_item].BackColor = Color.Red;

}

toolStart.Text = "Idle - " + DateTime.Now;

ping_thread.Abort();

}

}

private void frmMain_Shown(object sender, EventArgs e)

{

lstHosts.Columns.Add("Status");

lstHosts.Columns.Add("Where");

lstHosts.Columns.Add("time");

lstHosts.Columns.Add("ttl");

lstHosts.Columns[0].Text = "Status";

lstHosts.Columns[1].Text = "Where";

lstHosts.Columns[2].Text = "time";

lstHosts.Columns[3].Text = "ttl";

lstHosts.Columns[0].Width = 200;

lstHosts.Columns[1].Width = 200;

lstHosts.Columns[2].Width = 80;

lstHosts.Columns[3].Width = 80;

lstHosts.Columns[0].TextAlign = HorizontalAlignment.Left;

lstHosts.Columns[1].TextAlign = HorizontalAlignment.Left;

lstHosts.Columns[2].TextAlign = HorizontalAlignment.Center;

lstHosts.Columns[3].TextAlign = HorizontalAlignment.Center;

DataSet dsHosts = new DataSet("hosts");

dsHosts.ReadXml("C:\\Users\\Jassim\\Documents\\Visual Studio 2005\\Projects\\HostHealth\\hosts.xml");

foreach (DataRow drHosts in dsHosts.Tables[0].Rows)

{

lstHosts.Items.Add("Pending..");

lstHosts.Items[lstHosts.Items.Count - 1].SubItems.Add(drHosts["IPAddress"].ToString());

lstHosts.Items[lstHosts.Items.Count - 1].SubItems.Add("");

lstHosts.Items[lstHosts.Items.Count - 1].SubItems.Add("");

}

}

private void toolStart_Click(object sender, EventArgs e)

{

if (toolStart.Text == "START")

{

toolStatus.Text = "Idle";

toolStart.Text = "STOP!!";

toolStart.ForeColor = Color.Red;

toolStart.ToolTipText = " Stop Monitoring ";

timerPing.Enabled = true;

}

else

{

timerPing.Enabled = false;

toolStatus.Text = "Off";

toolStart.Text = "START";

toolStart.ForeColor = Color.Black;

toolStart.ToolTipText = " Start Monitoring ";

}

}

private void timerPing_Tick(object sender, EventArgs e)

{

this.ping_thread = new Thread(new ThreadStart(this.ping_to_host));

this.ping_thread.Start();


ping_to_host();

}

}

}
AnswerRe: can someone help plz: threading the PingReply Pin
Not Active25-Aug-06 8:43
mentorNot Active25-Aug-06 8:43 
QuestionC# ::: receive FAX Pin
Yetinger25-Aug-06 8:21
Yetinger25-Aug-06 8:21 
AnswerRe: C# ::: receive FAX Pin
Nader Elshehabi25-Aug-06 10:29
Nader Elshehabi25-Aug-06 10:29 
GeneralRe: C# ::: receive FAX Pin
Yetinger25-Aug-06 22:29
Yetinger25-Aug-06 22:29 
AnswerRe: C# ::: receive FAX Pin
Nader Elshehabi26-Aug-06 0:59
Nader Elshehabi26-Aug-06 0:59 
AnswerRe: C# ::: receive FAX Pin
Yetinger27-Aug-06 5:28
Yetinger27-Aug-06 5:28 
QuestionCrystal Reports and Windows Applications Pin
ebonaba25-Aug-06 7:59
ebonaba25-Aug-06 7:59 
QuestionPrinting to an Okidata printer Pin
tigerButterfly25-Aug-06 7:52
tigerButterfly25-Aug-06 7:52 
Question"Unadvising" Event Sink in VB6 Pin
Ilia Blank25-Aug-06 7:46
Ilia Blank25-Aug-06 7:46 
GeneralRe: "Unadvising" Event Sink in VB6 Pin
Guffa25-Aug-06 8:54
Guffa25-Aug-06 8:54 
QuestionGlobal DLL for all app components Pin
drdavef25-Aug-06 7:35
drdavef25-Aug-06 7:35 
AnswerRe: Global DLL for all app components Pin
Nader Elshehabi25-Aug-06 10:36
Nader Elshehabi25-Aug-06 10:36 
GeneralRe: Global DLL for all app components Pin
drdavef25-Aug-06 11:58
drdavef25-Aug-06 11:58 
GeneralRe: Global DLL for all app components Pin
Nader Elshehabi25-Aug-06 12:21
Nader Elshehabi25-Aug-06 12:21 
QuestionCrystal reports and SharpDevelop Pin
Evy_Soza25-Aug-06 7:02
Evy_Soza25-Aug-06 7:02 
Questionuse C# function in VB Pin
VK-Cadec25-Aug-06 3:57
VK-Cadec25-Aug-06 3:57 
AnswerRe: use C# function in VB Pin
Not Active25-Aug-06 4:08
mentorNot Active25-Aug-06 4:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.