示例#1
0
 public void Dispose()
 {
     _sessionWatcher.CancelAsync();
     while (_sessionWatcher.IsBusy)
     {
         SupportUtils.DoEvents();
     }
 }
示例#2
0
 private void LoggerMessageListChanged(object sender, string e)
 {
     if (!string.IsNullOrWhiteSpace(e))
     {
         SupportUtils.DoEvents(new Action(() => {
             _messageList.Add(e);
             MessageList.ScrollIntoView(e);
         }));
     }
 }
示例#3
0
 public void StopAll()
 {
     foreach (var worker in _workers.Values)
     {
         worker.CancelAsync();
     }
     while (_workers.Values.Any(t => t.IsBusy))
     {
         SupportUtils.DoEvents();
     }
 }
示例#4
0
 public void StopWorker(int siteId)
 {
     if (_workers.ContainsKey(siteId))
     {
         var worker = _workers[siteId];
         worker.CancelAsync();
         while (worker.IsBusy)
         {
             SupportUtils.DoEvents();
         }
     }
 }
示例#5
0
        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;
            }
        }