在我开始了解它的混乱之前,我先对其进行了整理,然后再进行清理。这也是出于我自己的知识增长,我无意在整个公司范围内推广。我已经制作了一个监视程序来检查我的一个客户端的几个服务器的状态。我已经设法从ping到服务器获取了我需要的所有相关数据,然后将数据发送到“ sort”方法,然后将其发送到下一个方法,该方法确定了我应该更改哪个标签的文本,它会放入这些if语句中,但是不会更新文本。
我已经尝试过:
Application.doEvents();
Label.Refresh();
Label.Update();
我也尝试过使用多线程,看看是否会迫使它通过。
我什至尝试使用按钮手动更新,但也没有用。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
Synergy s = new Synergy();
s.Start();
}
private void Label2_Click(object sender, EventArgs e)
{
}
public void Sort(String Name, double P, long RTT, String Response)
{
Console.WriteLine(Name + ": Inside Sort");
if (Name.Contains("SYN-"))
{
SynergySort(Name, P, RTT, Response);
}
}
public void SynergySort(String Name, double P, long RTT, String Response)
{
Console.WriteLine(Name + ": Inside Synergy Sort");
if (Name.Equals("SYN-DC01"))
{
Console.WriteLine(Name + ": Inside DC01 SORT");
this.SD1R.Text = RTT.ToString();
this.SD1P.Text = P.ToString();
}
else if (Name.Equals("SYN-DC03"))
{
Console.WriteLine(Name + ": Inside DC03 SORT");
this.SD3R.Text = RTT.ToString();
this.SD3P.Text = P.ToString();
}
}
}
public class Synergy
{
private Form1 f = new Form1();
private Pinger ping = new Pinger();
public void Start()
{
NAS01Scan();
DC03Scan();
TRACKERScan();
DC01Scan();
VoiceScan();
NETAPPScan();
}
public void NAS01Scan()
{
Console.WriteLine("Pinging NAS01");
ping.IP("172.16.xx.xxx", 5, "SYN-NAS01");
}
public void DC03Scan()
{
Console.WriteLine("pinging DC03");
ping.IP("172.16.xx.xxx", 5, "SYN-DC03");
}
public void TRACKERScan()
{
Console.WriteLine("pinging TRACKER");
ping.IP("172.16.xx.xxx", 5, "SYN-TRACKER");
}
public void DC01Scan()
{
Console.WriteLine("pinging DC01");
ping.IP("172.16.xx.xxx", 5, "SYN-DC01");
}
public void NETAPPScan()
{
Console.WriteLine("pinging NETAPP");
ping.IP("172.16.xx.xxx", 5, "SYN-NETAPP");
}
public void VoiceScan()
{
Console.WriteLine("pinging AVAYA_Voice");
ping.IP("172.16.xx.xxx", 5, "SYN-AVAYA_Voice");
}
}
public class Pinger
{
private Form1 f = new Form1();
public void IP(String host, int echoNum, String Name)
{
long totalTime = 0;
PingReply reply = null;
int timeout = 120;
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
options.DontFragment = true;
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int failed = 0;
for (int i = 0; i < echoNum; i++)
{
reply = pingSender.Send(host, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
}
else
{
failed += 1;
Console.WriteLine(Name + ": " + reply.Status);
}
}
totalTime += reply.RoundtripTime;
Console.WriteLine(Name + ": RoundTrip time: {0}", reply.RoundtripTime);
Console.WriteLine(Name + ": Time in MS = " + totalTime / echoNum);
double percent = (failed / echoNum) * 100;
Console.WriteLine(Name + ": Percent Loss is " + percent);
f.Sort(Name, percent, reply.RoundtripTime, reply.Status.ToString());
}
}