blob: d09d9a1338152db8c9da0b30b61a277fa5f16e92 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
using System;
using System.Threading;
using System.Net.NetworkInformation;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MyNet {
public partial class myNetForm : Form {
public myNetForm() {
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
Thread t = new Thread(PingStatus);
t.Start();
}
private void PingStatus() {
Ping p = new Ping();
PingReply pr;
while(true) {
try {
pr = p.Send(cbPingAddress.Text);
lblErrorMessage.Text = "";
if (pr.Status == IPStatus.Success) {
lblPing.Text = pr.RoundtripTime + "";
if (pr.RoundtripTime > 300) lblPing.BackColor = Color.Red;
else if (pr.RoundtripTime > 100) lblPing.BackColor = Color.Orange;
else if (pr.RoundtripTime > 10) lblPing.BackColor = Color.Yellow;
else lblPing.BackColor = Color.LightGreen;
}
else throw new Exception(pr.Status.ToString());
} catch (Exception ex) {
lblErrorMessage.Text = ex.Message;
lblPing.BackColor = Color.Red;
lblPing.Text = "-1";
}
Thread.Sleep(1000);
}
}
private void Form1_Load(object sender, EventArgs e) {
}
}
}
|