public void Dispose() { _sessionWatcher.CancelAsync(); while (_sessionWatcher.IsBusy) { SupportUtils.DoEvents(); } }
private void LoggerMessageListChanged(object sender, string e) { if (!string.IsNullOrWhiteSpace(e)) { SupportUtils.DoEvents(new Action(() => { _messageList.Add(e); MessageList.ScrollIntoView(e); })); } }
public void StopAll() { foreach (var worker in _workers.Values) { worker.CancelAsync(); } while (_workers.Values.Any(t => t.IsBusy)) { SupportUtils.DoEvents(); } }
public void StopWorker(int siteId) { if (_workers.ContainsKey(siteId)) { var worker = _workers[siteId]; worker.CancelAsync(); while (worker.IsBusy) { SupportUtils.DoEvents(); } } }
void WorkerDoWork(object sender, DoWorkEventArgs e) { var worker = sender as BackgroundWorker; var data = e.Argument as WebSiteItem; if (worker != null && data != null) { while (worker.CancellationPending == false) { var ping = new Ping(); try { var result = ping.Send(data.Url, PING_TIMEOUT); if (worker.CancellationPending) { continue; } if (result.Status == IPStatus.Success) { worker.ReportProgress((int)result.RoundtripTime, data); } else { worker.ReportProgress(0, data); } } catch (PingException ex) { if (ex.InnerException != null) { throw new Exception(ex.Message + " " + ex.InnerException.Message + " " + data.Url); } } if (worker.CancellationPending) { continue; } SupportUtils.DoEvents(); Thread.Sleep(data.PingInterval * MS_IN_SECOND); } e.Result = null; } }