Esempio n. 1
0
        private void PingCompletedCallback(object sender, PingCompletedEventArgs e)
        {
            if (!e.Reply.Address.Equals(default(IPAddress))) //Happens some times that the ip is 0 // && (e.Reply.Status == IPStatus.Success)
            {
                OnResult?.Invoke(this, e);
            }
            else
            {
                Logger.Log($"Invalid pingreply from pingObject");
            }

            var nextScanAddress = GetNext();

            if (nextScanAddress != null)
            {
                ((System.Net.NetworkInformation.Ping)sender).SendAsync(nextScanAddress, (int)TimeOut.TotalMilliseconds,
                                                                       new byte[32].Propagate((byte)'#'), _pingOptions);
            }
            else
            {
                lock (LockObject)
                {
                    _runningPingScanners--;

                    var pingCompleted = _runningPingScanners >= 0 && AddressCollectionQueue.IsEmpty;

                    if (pingCompleted)
                    {
                        OnPingFinished?.Invoke(this, new EventArgs());
                    }
                }
            }
        }
Esempio n. 2
0
 private void PingTimeoutCheckerCallback(object state)
 {
     lock (LockObject)
     {
         if (AddressCollectionQueue.IsEmpty && TimeOut < DateTime.Now.Subtract(_lastResult))
         {
             _timeoutTimer.Dispose();
             OnPingFinished?.Invoke(this, EventArgs.Empty);
         }
     }
 }