Ejemplo n.º 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);
         }
     });
 }
Ejemplo n.º 2
0
 public void Clear()
 {
     RoundtripTimeList.Clear();
     LostPackageNum = 0;
     RequestNum     = 0;
 }
Ejemplo n.º 3
0
 public long GetMaxRoundtripTime()
 {
     return(RoundtripTimeList.Max());
 }
Ejemplo n.º 4
0
 public long GetMinRoundtripTime()
 {
     return(RoundtripTimeList.Min());
 }
Ejemplo n.º 5
0
 public double GetAverageRoundtripTime()
 {
     return(RoundtripTimeList.Average());
 }