private void StartPerformanceTest(string moduleName, string commandName, string parameters, int executions, int commandTimeout) { if (!modules.ContainsKey(moduleName)) { return; } if ((executions < 0) || (executions > 1000000)) { return; } if (commandTimeout < 0) { commandTimeout = 0; } if (commandTimeout > 120000) { commandTimeout = 120000; } ConnectionManager cnnMan = modules[moduleName]; PerformanceTestWork work = new PerformanceTestWork(cnnMan, commandName, parameters, executions, commandTimeout); bgwPerformanceTestWorker.RunWorkerAsync(work); btnStartStopPerformanceTest.Text = "Stop Performance Test"; btnStartStopPerformanceTest.Enabled = true; }
private void bgwPerformanceTestWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { btnStartStopPerformanceTest.Text = "Start Performance Test"; btnStartStopPerformanceTest.Enabled = true; performanceTestInProgress = false; PerformanceTestWork work = e.Result as PerformanceTestWork; if (work == null) { return; } txtPerformanceTestElapsed.Text = work.Elapsed.ToString(); txtPerformanceTestSucceeded.Text = work.Succeeded.ToString(); }
private void StartPerformanceTest(string moduleName, string commandName, string parameters, int executions, int commandTimeout) { if (!modules.ContainsKey(moduleName)) return; if ((executions < 0)||(executions > 1000000)) return; if (commandTimeout < 0) commandTimeout = 0; if (commandTimeout > 120000) commandTimeout = 120000; ConnectionManager cnnMan = modules[moduleName]; PerformanceTestWork work = new PerformanceTestWork(cnnMan, commandName, parameters, executions, commandTimeout); bgwPerformanceTestWorker.RunWorkerAsync(work); btnStartStopPerformanceTest.Text = "Stop Performance Test"; btnStartStopPerformanceTest.Enabled = true; }
private void bgwPerformanceTestWorker_DoWork(object sender, DoWorkEventArgs e) { PerformanceTestWork work = e.Argument as PerformanceTestWork; if (work == null) { return; } int step; Stopwatch stepStopwatch = new Stopwatch(); Command command; Response candidate; bool found; performanceTestInProgress = true; stopwatch.Reset(); stopwatch.Start(); for (step = 0; running && !bgwPerformanceTestWorker.CancellationPending && (step < work.Executions); ++step) { work.Progress = 100 * step / work.Executions; bgwPerformanceTestWorker.ReportProgress(work.Progress, sender); command = new Command(work.ConnectionManager, work.CommandName, work.Parameters, step); // 1. Send the command. If command cannot be sent, return false lock (receivedResponses) { receivedResponses.Clear(); } stepStopwatch.Reset(); stepStopwatch.Start(); if (!work.ConnectionManager.Send(command)) { stepStopwatch.Stop(); continue; } // 2. Wait for response to arrival while (running && (stepStopwatch.ElapsedMilliseconds < work.CommandTimeout)) { found = false; lock (receivedResponses) { for (int i = 0; i < receivedResponses.Count; ++i) { candidate = receivedResponses[i]; if (command.IsMatch(candidate)) { receivedResponses.Remove(candidate); if (candidate.Success) { ++work.Succeeded; } found = true; break; } } } if (found) { break; } Thread.Sleep(1); } stepStopwatch.Stop(); work.Elapsed = stopwatch.Elapsed; } stopwatch.Stop(); e.Result = work; }