private void _backgroundWorker_BeginPing(object sender, DoWorkEventArgs e) { if (FieldsAreValid()) { ClearMonitor(); var backgroundWorker = (BackgroundWorker)sender; char pingStringDelimiter = ';'; string hostIPAddresss = txtHostIPAddress.Text; string logPath = txtLogPath.Text; int iterations = int.Parse(txtIterations.Text); int bytesToSend = int.Parse(txtBytesToSend.Text); int timeout = int.Parse(txtTimeout.Text); PingObject backgroundPingObject = new PingObject(hostIPAddresss, bytesToSend, timeout); SetGroup(grpPingSettings, false); EnableOrDisableControl(btnStopPing, true); UpdateLabel(lblOutput, ""); if (chkLog.Checked) { log = new PingLog(logPath, GetCurrentTimeStamp().Replace(":", "-")); } int loopCounter = 0; while (loopCounter < iterations) { if (backgroundWorker.CancellationPending) { e.Cancel = true; return; } bool pingSuccess = backgroundPingObject.DoOnePing(); UpdateDisplayedMetrics(backgroundPingObject); string pingString = GeneratePingString(pingStringDelimiter, backgroundPingObject.TotalPings, GetCurrentTimeStamp(), (pingSuccess ? "success" : "failure"), backgroundPingObject.LastRoundTripTime, backgroundPingObject.GoodRx, backgroundPingObject.BadRx, backgroundPingObject.PercentLoss); if (chkLog.Checked) { log.WriteLineToLog(pingString); } UpdateMonitor(pingString, pingStringDelimiter); AppendOutputText(pingString); Thread.Sleep(1000); if (optFinite.Checked) { loopCounter++; } } } else { MessageBox.Show("One of your fields is not right. Make sure all information is correctly filled out.", "Field empty error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void DoAPingTest() { Assert.IsTrue(testPingObject.DoOnePing()); }