Async multiple ping checking faild - Need Advance people

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hello there, i have a project, write long ago, it had only three option, but newly i chenge it functionality, so let 10 server check for ping automatically, and also let user to check ping one server on his own wish, but after adding this option when i press
this buttion every thing fail, and without any exception my program terminate...
i used ping class...
using System.Net.NetworkInformation;
Ping pingClient = new Ping();


Main functionality

<div style="color:black; background-color:white
<pre lang="x-c# <span style="color:blue #region Latency Check

<span style="color:blue #region Internet Availibility Check
<span style="color:green //Class InternetCS
<span style="color:blue #endregion

<span style="color:blue #region Ping check
<span style="color:blue private <span style="color:blue void pingClient_PingCompleted(<span style="color:blue object sender, System.Net.NetworkInformation.PingCompletedEventArgs e)
{
<span style="color:blue if (!InternetCS.InternetGetConnectedState())
{
b3.Enabled = <span style="color:blue true;
pingStatusPanel1.BackColor = Color.FromArgb(255, 50, 50, 50);
pingStatusPanel2.BackColor = Color.FromArgb(255, 50, 50, 50);
pingStatusPanel3.BackColor = Color.FromArgb(255, 50, 50, 50);
pingStatusPanel4.BackColor = Color.FromArgb(255, 50, 50, 50);
pingStatusPanel5.BackColor = Color.FromArgb(255, 50, 50, 50);
pingStatusPanel6.BackColor = Color.FromArgb(255, 50, 50, 50);
pingStatusPanel7.BackColor = Color.FromArgb(255, 50, 50, 50);
pingStatusPanel8.BackColor = Color.FromArgb(255, 50, 50, 50);
pingStatusPanel9.BackColor = Color.FromArgb(255, 50, 50, 50);
pingStatusPanel10.BackColor = Color.FromArgb(255, 50, 50, 50);
pingStatusPanelSingle.BackColor = Color.FromArgb(255, 50, 50, 50);
strPingTooltip1 = <span style="color:#a31515 "No Internet Access";
strPingTooltip2 = <span style="color:#a31515 "No Internet Access";
strPingTooltip3 = <span style="color:#a31515 "No Internet Access";
strPingTooltip4 = <span style="color:#a31515 "No Internet Access";
strPingTooltip5 = <span style="color:#a31515 "No Internet Access";
strPingTooltip6 = <span style="color:#a31515 "No Internet Access";
strPingTooltip7 = <span style="color:#a31515 "No Internet Access";
strPingTooltip8 = <span style="color:#a31515 "No Internet Access";
strPingTooltip9 = <span style="color:#a31515 "No Internet Access";
strPingTooltip10 = <span style="color:#a31515 "No Internet Access";
strPingTooltipSingle = <span style="color:#a31515 "No Internet Access";
<span style="color:blue return;
}
<span style="color:blue else
{
<span style="color:blue if (pingStatusPanel1.BackColor == Color.FromArgb(255, 50, 50, 50))
{
pingStatusPanel1.BackColor = Color.Silver;
strPingTooltip1 = <span style="color:#a31515 "";
}
<span style="color:blue if (pingStatusPanel2.BackColor == Color.FromArgb(255, 50, 50, 50))
{
strPingTooltip2 = <span style="color:#a31515 "";
pingStatusPanel2.BackColor = Color.Silver;
}
<span style="color:blue if (pingStatusPanel3.BackColor == Color.FromArgb(255, 50, 50, 50))
{
strPingTooltip3 = <span style="color:#a31515 "";
pingStatusPanel3.BackColor = Color.Silver;
}
<span style="color:blue if (pingStatusPanel4.BackColor == Color.FromArgb(255, 50, 50, 50))
{
strPingTooltip4 = <span style="color:#a31515 "";
pingStatusPanel4.BackColor = Color.Silver;
}
<span style="color:blue if (pingStatusPanel5.BackColor == Color.FromArgb(255, 50, 50, 50))
{
strPingTooltip5 = <span style="color:#a31515 "";
pingStatusPanel5.BackColor = Color.Silver;
}
<span style="color:blue if (pingStatusPanel6.BackColor == Color.FromArgb(255, 50, 50, 50))
{
strPingTooltip6 = <span style="color:#a31515 "";
pingStatusPanel6.BackColor = Color.Silver;
}
<span style="color:blue if (pingStatusPanel7.BackColor == Color.FromArgb(255, 50, 50, 50))
{
strPingTooltip7 = <span style="color:#a31515 "";
pingStatusPanel7.BackColor = Color.Silver;
}
<span style="color:blue if (pingStatusPanel8.BackColor == Color.FromArgb(255, 50, 50, 50))
{
strPingTooltip8 = <span style="color:#a31515 "";
pingStatusPanel8.BackColor = Color.Silver;
}
<span style="color:blue if (pingStatusPanel9.BackColor == Color.FromArgb(255, 50, 50, 50))
{
strPingTooltip9 = <span style="color:#a31515 "";
pingStatusPanel9.BackColor = Color.Silver;
}
<span style="color:blue if (pingStatusPanel10.BackColor == Color.FromArgb(255, 50, 50, 50))
{
strPingTooltip10 = <span style="color:#a31515 "";
pingStatusPanel10.BackColor = Color.Silver;
}
<span style="color:blue if (pingStatusPanelSingle.BackColor == Color.FromArgb(255, 50, 50, 50))
{
strPingTooltipSingle = <span style="color:#a31515 "";
pingStatusPanelSingle.BackColor = Color.Silver;
}
}
<span style="color:blue string server = (<span style="color:blue string)e.UserState;
<span style="color:blue int _itemNum = 0;
<span style="color:blue if (pingStatusPanel1.Tag.ToString().ToLower() == server.ToLower())
{
_itemNum = 1;
}
<span style="color:blue else <span style="color:blue if (pingStatusPanel2.Tag.ToString().ToLower() == server.ToLower())
{
_itemNum = 2;
}
<span style="color:blue else <span style="color:blue if (pingStatusPanel3.Tag.ToString().ToLower() == server.ToLower())
{
_itemNum = 3;
}
<span style="color:blue else <span style="color:blue if (pingStatusPanel4.Tag.ToString().ToLower() == server.ToLower())
{
_itemNum = 4;
}
<span style="color:blue else <span style="color:blue if (pingStatusPanel5.Tag.ToString().ToLower() == server.ToLower())
{
_itemNum = 5;
}
<span style="color:blue else <span style="color:blue if (pingStatusPanel6.Tag.ToString().ToLower() == server.ToLower())
{
_itemNum = 6;
}
<span style="color:blue else <span style="color:blue if (pingStatusPanel7.Tag.ToString().ToLower() == server.ToLower())
{
_itemNum = 7;
}
<span style="color:blue else <span style="color:blue if (pingStatusPanel8.Tag.ToString().ToLower() == server.ToLower())
{
_itemNum = 8;
}
<span style="color:blue else <span style="color:blue if (pingStatusPanel9.Tag.ToString().ToLower() == server.ToLower())
{
_itemNum = 9;
}
<span style="color:blue else <span style="color:blue if (pingStatusPanel10.Tag.ToString().ToLower() == server.ToLower())
{
_itemNum = 10;
}
<span style="color:blue else <span style="color:blue if (pingStatusPanelSingle.Tag.ToString().ToLower() == server.ToLower())
{
_itemNum = 11;
}
<span style="color:green // Check to see if an error occurred. If no error, then display
<span style="color:green // the address used and the ping time in milliseconds.
<span style="color:blue try
{
<span style="color:blue if (e.Error == <span style="color:blue null)
{
<span style="color:blue if (e.Cancelled)
{
<span style="color:green //pingDetailsTextBox.Text += " Ping cancelled. rn";
<span style="color:blue switch (_itemNum)
{
<span style="color:blue case 1:
pingStatusPanel1.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip1 = <span style="color:#a31515 "Ping Canceled";
<span style="color:blue break;
<span style="color:blue case 2:
pingStatusPanel2.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip2 = <span style="color:#a31515 "Ping Canceled";
<span style="color:blue break;
<span style="color:blue case 3:
pingStatusPanel3.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip3 = <span style="color:#a31515 "Ping Canceled";
<span style="color:blue break;
<span style="color:blue case 4:
pingStatusPanel4.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip4 = <span style="color:#a31515 "Ping Canceled";
<span style="color:blue break;
<span style="color:blue case 5:
pingStatusPanel5.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip5 = <span style="color:#a31515 "Ping Canceled";
<span style="color:blue break;
<span style="color:blue case 6:
pingStatusPanel6.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip6 = <span style="color:#a31515 "Ping Canceled";
<span style="color:blue break;
<span style="color:blue case 7:
pingStatusPanel7.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip7 = <span style="color:#a31515 "Ping Canceled";
<span style="color:blue break;
<span style="color:blue case 8:
pingStatusPanel8.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip8 = <span style="color:#a31515 "Ping Canceled";
<span style="color:blue break;
<span style="color:blue case 9:
pingStatusPanel9.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip9 = <span style="color:#a31515 "Ping Canceled";
<span style="color:blue break;
<span style="color:blue case 10:
pingStatusPanel10.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip10 = <span style="color:#a31515 "Ping Canceled";
<span style="color:blue break;
<span style="color:blue case 11:
pingStatusPanelSingle.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltipSingle = <span style="color:#a31515 "Ping Canceled";
<span style="color:blue break;
}
}
<span style="color:blue else
{
<span style="color:blue if (e.Reply.Status == IPStatus.Success)
{
<span style="color:green //pingDetailsTextBox.Text +=
<span style="color:green // " " + e.Reply.Address.ToString() + " " +
<span style="color:green // e.Reply.RoundtripTime.ToString(
<span style="color:green // NumberFormatInfo.CurrentInfo) + "ms" + "rn";
<span style="color:blue if (e.Reply.RoundtripTime <= 150)
{
<span style="color:blue switch (_itemNum)
{
<span style="color:blue case 1:
pingStatusPanel1.BackColor = Color.FromArgb(255, 0, 255, 0);
strPingTooltip1 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 2:
pingStatusPanel2.BackColor = Color.FromArgb(255, 0, 255, 0);
strPingTooltip2 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 3:
pingStatusPanel3.BackColor = Color.FromArgb(255, 0, 255, 0);
strPingTooltip3 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 4:
pingStatusPanel4.BackColor = Color.FromArgb(255, 0, 255, 0);
strPingTooltip4 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 5:
pingStatusPanel5.BackColor = Color.FromArgb(255, 0, 255, 0);
strPingTooltip5 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 6:
pingStatusPanel6.BackColor = Color.FromArgb(255, 0, 255, 0);
strPingTooltip6 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 7:
pingStatusPanel7.BackColor = Color.FromArgb(255, 0, 255, 0);
strPingTooltip7 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 8:
pingStatusPanel8.BackColor = Color.FromArgb(255, 0, 255, 0);
strPingTooltip8 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 9:
pingStatusPanel9.BackColor = Color.FromArgb(255, 0, 255, 0);
strPingTooltip9 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 10:
pingStatusPanel10.BackColor = Color.FromArgb(255, 0, 255, 0);
strPingTooltip10 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 11:
pingStatusPanelSingle.BackColor = Color.FromArgb(255, 0, 255, 0);
strPingTooltipSingle = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
}
}
<span style="color:blue else <span style="color:blue if (e.Reply.RoundtripTime > 150 && e.Reply.RoundtripTime < 750)
{
<span style="color:blue switch (_itemNum)
{
<span style="color:blue case 1:
pingStatusPanel1.BackColor = Color.FromArgb(255, Convert.ToInt32((e.Reply.RoundtripTime / 3) - 50), Convert.ToInt32(255 - ((e.Reply.RoundtripTime / 3) - 50)), 0);
strPingTooltip1 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 2:
pingStatusPanel2.BackColor = Color.FromArgb(255, Convert.ToInt32((e.Reply.RoundtripTime / 3) - 50), Convert.ToInt32(255 - ((e.Reply.RoundtripTime / 3) - 50)), 0);
strPingTooltip2 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 3:
pingStatusPanel3.BackColor = Color.FromArgb(255, Convert.ToInt32((e.Reply.RoundtripTime / 3) - 50), Convert.ToInt32(255 - ((e.Reply.RoundtripTime / 3) - 50)), 0);
strPingTooltip3 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 4:
pingStatusPanel4.BackColor = Color.FromArgb(255, Convert.ToInt32((e.Reply.RoundtripTime / 3) - 50), Convert.ToInt32(255 - ((e.Reply.RoundtripTime / 3) - 50)), 0);
strPingTooltip4 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 5:
pingStatusPanel5.BackColor = Color.FromArgb(255, Convert.ToInt32((e.Reply.RoundtripTime / 3) - 50), Convert.ToInt32(255 - ((e.Reply.RoundtripTime / 3) - 50)), 0);
strPingTooltip5 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 6:
pingStatusPanel6.BackColor = Color.FromArgb(255, Convert.ToInt32((e.Reply.RoundtripTime / 3) - 50), Convert.ToInt32(255 - ((e.Reply.RoundtripTime / 3) - 50)), 0);
strPingTooltip6 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 7:
pingStatusPanel7.BackColor = Color.FromArgb(255, Convert.ToInt32((e.Reply.RoundtripTime / 3) - 50), Convert.ToInt32(255 - ((e.Reply.RoundtripTime / 3) - 50)), 0);
strPingTooltip7 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 8:
pingStatusPanel8.BackColor = Color.FromArgb(255, Convert.ToInt32((e.Reply.RoundtripTime / 3) - 50), Convert.ToInt32(255 - ((e.Reply.RoundtripTime / 3) - 50)), 0);
strPingTooltip8 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 9:
pingStatusPanel9.BackColor = Color.FromArgb(255, Convert.ToInt32((e.Reply.RoundtripTime / 3) - 50), Convert.ToInt32(255 - ((e.Reply.RoundtripTime / 3) - 50)), 0);
strPingTooltip9 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 10:
pingStatusPanel10.BackColor = Color.FromArgb(255, Convert.ToInt32((e.Reply.RoundtripTime / 3) - 50), Convert.ToInt32(255 - ((e.Reply.RoundtripTime / 3) - 50)), 0);
strPingTooltip10 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 11:
pingStatusPanelSingle.BackColor = Color.FromArgb(255, Convert.ToInt32((e.Reply.RoundtripTime / 3) - 50), Convert.ToInt32(255 - ((e.Reply.RoundtripTime / 3) - 50)), 0);
strPingTooltipSingle = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
}
}
<span style="color:blue else <span style="color:blue if (e.Reply.RoundtripTime >= 750)
{
<span style="color:blue switch (_itemNum)
{
<span style="color:blue case 1:
pingStatusPanel1.BackColor = Color.FromArgb(255, 255, 0, 0);
strPingTooltip1 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 2:
pingStatusPanel2.BackColor = Color.FromArgb(255, 255, 0, 0);
strPingTooltip2 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 3:
pingStatusPanel3.BackColor = Color.FromArgb(255, 255, 0, 0);
strPingTooltip3 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 4:
pingStatusPanel4.BackColor = Color.FromArgb(255, 255, 0, 0);
strPingTooltip4 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 5:
pingStatusPanel5.BackColor = Color.FromArgb(255, 255, 0, 0);
strPingTooltip5 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 6:
pingStatusPanel6.BackColor = Color.FromArgb(255, 255, 0, 0);
strPingTooltip6 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 7:
pingStatusPanel7.BackColor = Color.FromArgb(255, 255, 0, 0);
strPingTooltip7 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 8:
pingStatusPanel8.BackColor = Color.FromArgb(255, 255, 0, 0);
strPingTooltip8 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 9:
pingStatusPanel9.BackColor = Color.FromArgb(255, 255, 0, 0);
strPingTooltip9 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 10:
pingStatusPanel10.BackColor = Color.FromArgb(255, 255, 0, 0);
strPingTooltip10 = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
<span style="color:blue case 11:
pingStatusPanelSingle.BackColor = Color.FromArgb(255, 255, 0, 0);
strPingTooltipSingle = <span style="color:#a31515 "Ping is " + e.Reply.RoundtripTime + <span style="color:#a31515 " ms";
<span style="color:blue break;
}
}
}
<span style="color:blue else
{
<span style="color:green //pingDetailsTextBox.Text +=
<span style="color:green // " " + GetStatusString(e.Reply.Status) + "rn";
<span style="color:blue if (e.Reply.Status == IPStatus.TimedOut)
{
<span style="color:blue switch (_itemNum)
{
<span style="color:blue case 1:
pingStatusPanel1.BackColor = Color.FromArgb(255, 128, 0, 0);
strPingTooltip1 = <span style="color:#a31515 "Time Out";
<span style="color:blue break;
<span style="color:blue case 2:
pingStatusPanel2.BackColor = Color.FromArgb(255, 128, 0, 0);
strPingTooltip2 = <span style="color:#a31515 "Time Out";
<span style="color:blue break;
<span style="color:blue case 3:
pingStatusPanel3.BackColor = Color.FromArgb(255, 128, 0, 0);
strPingTooltip3 = <span style="color:#a31515 "Time Out";
<span style="color:blue break;
<span style="color:blue case 4:
pingStatusPanel4.BackColor = Color.FromArgb(255, 128, 0, 0);
strPingTooltip4 = <span style="color:#a31515 "Time Out";
<span style="color:blue break;
<span style="color:blue case 5:
pingStatusPanel5.BackColor = Color.FromArgb(255, 128, 0, 0);
strPingTooltip5 = <span style="color:#a31515 "Time Out";
<span style="color:blue break;
<span style="color:blue case 6:
pingStatusPanel6.BackColor = Color.FromArgb(255, 128, 0, 0);
strPingTooltip6 = <span style="color:#a31515 "Time Out";
<span style="color:blue break;
<span style="color:blue case 7:
pingStatusPanel7.BackColor = Color.FromArgb(255, 128, 0, 0);
strPingTooltip7 = <span style="color:#a31515 "Time Out";
<span style="color:blue break;
<span style="color:blue case 8:
pingStatusPanel8.BackColor = Color.FromArgb(255, 128, 0, 0);
strPingTooltip8 = <span style="color:#a31515 "Time Out";
<span style="color:blue break;
<span style="color:blue case 9:
pingStatusPanel9.BackColor = Color.FromArgb(255, 128, 0, 0);
strPingTooltip9 = <span style="color:#a31515 "Time Out";
<span style="color:blue break;
<span style="color:blue case 10:
pingStatusPanel10.BackColor = Color.FromArgb(255, 128, 0, 0);
strPingTooltip10 = <span style="color:#a31515 "Time Out";
<span style="color:blue break;
<span style="color:blue case 11:
pingStatusPanelSingle.BackColor = Color.FromArgb(255, 128, 0, 0);
strPingTooltipSingle = <span style="color:#a31515 "Time Out";
<span style="color:blue break;
}
}
<span style="color:blue else
{
<span style="color:blue switch (_itemNum)
{
<span style="color:blue case 1:
pingStatusPanel1.BackColor = Color.FromArgb(255, 0, 0, 0);
strPingTooltip1 = GetStatusString(e.Reply.Status);
<span style="color:blue break;
<span style="color:blue case 2:
pingStatusPanel2.BackColor = Color.FromArgb(255, 0, 0, 0);
strPingTooltip2 = GetStatusString(e.Reply.Status);
<span style="color:blue break;
<span style="color:blue case 3:
pingStatusPanel3.BackColor = Color.FromArgb(255, 0, 0, 0);
strPingTooltip3 = GetStatusString(e.Reply.Status);
<span style="color:blue break;
<span style="color:blue case 4:
pingStatusPanel4.BackColor = Color.FromArgb(255, 0, 0, 0);
strPingTooltip4 = GetStatusString(e.Reply.Status);
<span style="color:blue break;
<span style="color:blue case 5:
pingStatusPanel5.BackColor = Color.FromArgb(255, 0, 0, 0);
strPingTooltip5 = GetStatusString(e.Reply.Status);
<span style="color:blue break;
<span style="color:blue case 6:
pingStatusPanel6.BackColor = Color.FromArgb(255, 0, 0, 0);
strPingTooltip6 = GetStatusString(e.Reply.Status);
<span style="color:blue break;
<span style="color:blue case 7:
pingStatusPanel7.BackColor = Color.FromArgb(255, 0, 0, 0);
strPingTooltip7 = GetStatusString(e.Reply.Status);
<span style="color:blue break;
<span style="color:blue case 8:
pingStatusPanel8.BackColor = Color.FromArgb(255, 0, 0, 0);
strPingTooltip8 = GetStatusString(e.Reply.Status);
<span style="color:blue break;
<span style="color:blue case 9:
pingStatusPanel9.BackColor = Color.FromArgb(255, 0, 0, 0);
strPingTooltip9 = GetStatusString(e.Reply.Status);
<span style="color:blue break;
<span style="color:blue case 10:
pingStatusPanel10.BackColor = Color.FromArgb(255, 0, 0, 0);
strPingTooltip10 = GetStatusString(e.Reply.Status);
<span style="color:blue break;
<span style="color:blue case 11:
pingStatusPanelSingle.BackColor = Color.FromArgb(255, 0, 0, 0);
strPingTooltipSingle = GetStatusString(e.Reply.Status);
<span style="color:blue break;
}
}
}
}
}
<span style="color:blue else
{
<span style="color:green // Otherwise display the error.
<span style="color:green //pingDetailsTextBox.Text += " Ping error.rn";
<span style="color:green //MessageBox.Show(
<span style="color:green // "An error occurred while sending this ping. " +
<span style="color:green // e.Error.InnerException.Message);
<span style="color:blue switch (_itemNum)
{
<span style="color:blue case 1:
pingStatusPanel1.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip1 = <span style="color:#a31515 "Ping error.rn" + e.Error.InnerException.Message;
<span style="color:blue break;
<span style="color:blue case 2:
pingStatusPanel2.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip2 = <span style="color:#a31515 "Ping error.rn" + e.Error.InnerException.Message;
<span style="color:blue break;
<span style="color:blue case 3:
pingStatusPanel3.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip3 = <span style="color:#a31515 "Ping error.rn" + e.Error.InnerException.Message;
<span style="color:blue break;
<span style="color:blue case 4:
pingStatusPanel4.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip4 = <span style="color:#a31515 "Ping error.rn" + e.Error.InnerException.Message;
<span style="color:blue break;
<span style="color:blue case 5:
pingStatusPanel5.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip5 = <span style="color:#a31515 "Ping error.rn" + e.Error.InnerException.Message;
<span style="color:blue break;
<span style="color:blue case 6:
pingStatusPanel6.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip6 = <span style="color:#a31515 "Ping error.rn" + e.Error.InnerException.Message;
<span style="color:blue break;
<span style="color:blue case 7:
pingStatusPanel7.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip7 = <span style="color:#a31515 "Ping error.rn" + e.Error.InnerException.Message;
<span style="color:blue break;
<span style="color:blue case 8:
pingStatusPanel8.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip8 = <span style="color:#a31515 "Ping error.rn" + e.Error.InnerException.Message;
<span style="color:blue break;
<span style="color:blue case 9:
pingStatusPanel9.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip9 = <span style="color:#a31515 "Ping error.rn" + e.Error.InnerException.Message;
<span style="color:blue break;
<span style="color:blue case 10:
pingStatusPanel10.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltip10 = <span style="color:#a31515 "Ping error.rn" + e.Error.InnerException.Message;
<span style="color:blue break;
<span style="color:blue case 11:
pingStatusPanelSingle.BackColor = Color.FromArgb(255, 128, 128, 128);
strPingTooltipSingle = <span style="color:#a31515 "Ping error.rn" + e.Error.InnerException.Message;
<span style="color:blue break;
}
}
}
<span style="color:blue catch (Exception ex)
{
}
b3.Enabled = <span style="color:blue true;
}

<span style="color:blue private <span style="color:blue string GetStatusString(IPStatus status)
{
<span style="color:blue switch (status)
{
<span style="color:blue case IPStatus.Success:
<span style="color:blue return <span style="color:#a31515 "Success.";
<span style="color:blue case IPStatus.DestinationHostUnreachable:
<span style="color:blue return <span style="color:#a31515 "Destination host unreachable.";
<span style="color:blue case IPStatus.DestinationNetworkUnreachable:
<span style="color:blue return <span style="color:#a31515 "Destination network unreachable.";
<span style="color:blue case IPStatus.DestinationPortUnreachable:
<span style="color:blue return <span style="color:#a31515 "Destination port unreachable.";
<span style="color:blue case IPStatus.DestinationProtocolUnreachable:
<span style="color:blue return <span style="color:#a31515 "Destination protocol unreachable.";
<span style="color:blue case IPStatus.PacketTooBig:
<span style="color:blue return <span style="color:#a31515 "Packet too big.";
<span style="color:blue case IPStatus.TtlExpired:
<span style="color:blue return <span style="color:#a31515 "TTL expired.";
<span style="color:blue case IPStatus.ParameterProblem:
<span style="color:blue return <span style="color:#a31515 "Parameter problem.";
<span style="color:blue case IPStatus.SourceQuench:
<span style="color:blue return <span style="color:#a31515 "Source quench.";
<span style="color:blue case IPStatus.TimedOut:
<span style="color:blue return <span style="color:#a31515 "Timed out.";
<span style="color:blue default:
<span style="color:blue return <span style="color:#a31515 "Ping failed.";
}
}

<span style="color:green /*
private void p_PingCompleted(object sender, System.Net.NetworkInformation.PingCompletedEventArgs e)
{
if (e.Error == null)
{
string server = e.UserState.ToString();
//server holds the name of the server and you can then find the right panel with that name as tag.
//e.Reply.RoundtripTime.ToString() gives u pingtime if u want
//e.Reply.Status.ToString() gives status in text

if (e.Reply.Status == IPStatus.Success)
{

foreach (Control panel in this.Controls)
{
if (panel.GetType() == typeof(Panel))
{
if (panel.Tag.ToString().ToLower() == server.ToLower())
{
//do your stuff ok
panel.BackColor = Color.FromArgb(128, 0, 255, 0);
}
}

}
}
else
{
foreach (Control panel in this.Controls)
{
if (panel.GetType() == typeof(Panel))
{
if (panel.Tag.ToString().ToLower() == server.ToLower())
{
//do your error stuff
panel.BackColor = Color.FromArgb(128, 128, 128, 128);
}
}
}
}
}


}*/
<span style="color:blue #endregion

<span style="color:blue #endregion
[/code]

continue in next thread
<br/>

View the full article
 
Back
Top