// Demo Code for running by multi threads private static void RunTestByMultiThread(int threadCount) { QPSTestDemo demo = new QPSTestDemo(); var runTasks = new Task[threadCount]; for (int i = 0; i < threadCount; i++) { runTasks[i] = Task.Run(async() => await demo.RunTest()); } Task.WaitAll(runTasks); }
private static void RunTestByMultiThread(int threadCount, int seconds, HttpClient client, string url, string requestMethod, string token, string reqeustContent = null) { QPSTestDemo demo = new QPSTestDemo(); var runTasks = new Task <int> [threadCount]; for (int i = 0; i < threadCount; i++) { runTasks[i] = Task.Run(async() => await demo.GetRequestCount(seconds, client, url, requestMethod, token, reqeustContent)); } Task.WaitAll(runTasks); int sum = 0; for (int i = 0; i < threadCount; i++) { sum += runTasks[i].Result; } Console.WriteLine($"Request sum: {sum}"); }