public class PingChangeMonitor : ChangeMonitor
{
private string _uniqueId;
private string ipAddress;
private Timer timer;
/// <param name="interval">Timer interval in miliseconds</param>
public PingChangeMonitor(string ipAddress, double interval)
{
_uniqueId = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
this.ipAddress = ipAddress;
timer = new Timer(interval);
timer.Enabled = true;
timer.Elapsed += Timer_Elapsed;
base.InitializationComplete();
}
private void Timer_Elapsed( object sender, ElapsedEventArgs e )
{
Ping ping = new Ping();
var reply = ping.Send(ipAddress);
if(reply.Status != IPStatus.Success)
OnChanged(null);
}
public override string UniqueId
{
get { return _uniqueId; }
}
protected override void Dispose( bool disposing )
{
}
}