diff options
| author | Syndamia <kami02882@gmail.com> | 2019-11-16 19:04:59 +0200 |
|---|---|---|
| committer | Syndamia <kami02882@gmail.com> | 2019-11-16 19:04:59 +0200 |
| commit | 680e83d2972330206fa75171a00d50a1a80402d5 (patch) | |
| tree | 2b765aa201d0c0705d1adcc6021df3de333749b6 /Pinger/MyNet/Form1.cs | |
| parent | ea771ca5f29fcdf3c401c1748b6fce9afcb0a3a7 (diff) | |
| download | Shower-680e83d2972330206fa75171a00d50a1a80402d5.tar Shower-680e83d2972330206fa75171a00d50a1a80402d5.tar.gz Shower-680e83d2972330206fa75171a00d50a1a80402d5.zip | |
Did a small project called Pinger. The app pings a certain address and says the value.
Diffstat (limited to 'Pinger/MyNet/Form1.cs')
| -rw-r--r-- | Pinger/MyNet/Form1.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Pinger/MyNet/Form1.cs b/Pinger/MyNet/Form1.cs new file mode 100644 index 0000000..d09d9a1 --- /dev/null +++ b/Pinger/MyNet/Form1.cs @@ -0,0 +1,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) { + } + } +} |
