private Pinger() { status = WebsiteStatus.Unknown; timer = new Timer(); timer.Interval = 1000; timer.AutoReset = true; timer.Elapsed += timer_Elapsed; timer.Start(); }
void timer_Elapsed(object sender, ElapsedEventArgs e) { if (isWebSiteAvailable("http://konachan.com/")) { if (status != WebsiteStatus.Up) { var previousStatus = status; status = WebsiteStatus.Up; onWebsiteStatusChanged(previousStatus, status); } } else { if (status != WebsiteStatus.Down) { var previousStatus = status; status = WebsiteStatus.Down; onWebsiteStatusChanged(previousStatus, status); } } }
private void onWebsiteStatusChanged(WebsiteStatus changedFrom, WebsiteStatus changedTo) { if (WebsiteStatusChanged != null) { var args = new WebsiteStatusEventArgs(); args.ChangedFrom = changedFrom; args.ChangedTo = changedTo; WebsiteStatusChanged(this, args); } }