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