Testing Network Connection in C#
Hey,
I am trying to make some code to test wheter or not a my computer is connected to a network - this is what I have but it does not work - it always returns true - ie "Connection is alive".
// timer initialization
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Interval = 3000; // test in an interval of 3 sec
timer.Tick += new System.EventHandler(this.TestForNetwork);
timer.Start();
// Timer Tick event
protected void TestForNetwork(object sender, System.EventArgs e)
{
this.listBox1.Items.Add(System.Windows.Forms.SystemInformation.Network ? "Connection is alive" : "Connection lost");
}
The computer is connected on an ethernet network not a diap-up connection - does anybody have any idea what I am doing wrong and what I could be doing right!?!?
Thanks!
John.