Imported 1.1.0.0 BETA 2

- Very crude implementation of continuous background ping.
This commit is contained in:
2019-03-05 21:03:37 +00:00
parent 9bb6d80782
commit 7192a2d3e8
10 changed files with 239 additions and 66 deletions
+50
View File
@@ -0,0 +1,50 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;
namespace TimedShutdown
{
public class PingWidget
{
IPAddress _ipAddress = IPAddress.None;
public bool IsCancellationRequested { get; set; } = false;
BackgroundWorker contPingBackgroundWorker = new BackgroundWorker();
public void InitatePingRequest(IPAddress ipAddress)
{
_ipAddress = ipAddress;
contPingBackgroundWorker.DoWork += ContPingBackgroundWorkerDoWork;
contPingBackgroundWorker.RunWorkerAsync();
}
/// <summary>
/// Will continuously ping the input IP address every 5 seconds,
/// will stop if a cancellation request is made.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ContPingBackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
{
while (IsCancellationRequested == false)
{
Thread.Sleep(5000);
Ping pingSender = new Ping();
IPAddress address = _ipAddress;
PingReply reply = pingSender.Send(address);
if (reply.Status == IPStatus.Success)
Debug.WriteLine("Ping Success!");
else
{
Debug.WriteLine(reply.Status);
}
}
}
}
}