I have an application which contains a listview that has a list of IP address, i'm using Ping.SendAsync to ping the addresses.
private void timer1_Tick(object sender, EventArgs e)
{
foreach (ListViewItem lvitem in listView1.Items)
{
string input = lvitem.Text; ;
string ip = input ;
Ping pingSender = new Ping();
pingSender.PingCompleted += new PingCompletedEventHandler(ping_PingCompleted);
pingSender.SendAsync(ip, 1000, lvitem);
((IDisposable)pingSender).Dispose();
}
}
private static void ping_PingCompleted(object sender, PingCompletedEventArgs e)
{
ListViewItem lvitem = e.UserState as ListViewItem;
if (e.Reply.Status == IPStatus.Success)
{
lvitem.ImageIndex = 0; //a "check" image
}
else
{
lvitem.ImageIndex = 1; //a "X" image
}
GC.Collect();
}
I have 2 results right now, if it's a success or if it's something else. Timed out requests are common on some of the IP address but they'll return a reply most of the time, I want to display a different image if I haven't gotten a success reply from an ip address for a long time, how can I do this?