Пример #1
0
 public async void SendRequestsUntilStopping(string address, int timeout, byte[] buffer, PingOptions options)
 {
     await Task.Factory.StartNew(() =>
     {
         try
         {
             Ping pingSender = new Ping();
             while (IsToContinueSending)
             {
                 PingReply reply = pingSender.Send(address, timeout, buffer, options);
                 if (reply.Status == IPStatus.Success)
                 {
                     RoundtripTimeList.Add(reply.RoundtripTime);
                     var requestItem = new RequestItem(reply.Address.ToString(), reply.RoundtripTime);
                     RequestCompleted.Invoke(requestItem);
                 }
                 else
                 {
                     LostPackageNum++;
                     var requestItem = new RequestItem("Ping failed", -1);
                     RequestCompleted.Invoke(requestItem);
                 }
                 RequestNum++;
             }
             AllRequestsCompleted.Invoke();
         }
         catch (System.Net.NetworkInformation.PingException)
         {
             System.Windows.MessageBox.Show("Error sending request. Check the parameters are correct.", "Error",
                                            System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
         }
         catch (System.ArgumentNullException)
         {
             System.Windows.MessageBox.Show("Not all parameters are entered for the request", "Error",
                                            System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
         }
         catch
         {
             System.Windows.MessageBox.Show("Some error sending request", "Error",
                                            System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
         }
     });
 }
Пример #2
0
 public void Clear()
 {
     RoundtripTimeList.Clear();
     LostPackageNum = 0;
     RequestNum     = 0;
 }
Пример #3
0
 public long GetMaxRoundtripTime()
 {
     return(RoundtripTimeList.Max());
 }
Пример #4
0
 public long GetMinRoundtripTime()
 {
     return(RoundtripTimeList.Min());
 }
Пример #5
0
 public double GetAverageRoundtripTime()
 {
     return(RoundtripTimeList.Average());
 }