private async Task RunAsync(CancellationToken cancellationToken) { ILogger logger = new ApplicationInsightsLogger(); string brokerIp; int numberOfThreads; try { brokerIp = CloudConfigurationManager.GetSetting("BrokerIp"); var threadSet = int.TryParse(CloudConfigurationManager.GetSetting("Threads"), out numberOfThreads); if (!threadSet) { numberOfThreads = DefaultNumberOfThreads; } } catch (Exception exception) { brokerIp = string.Empty; numberOfThreads = DefaultNumberOfThreads; logger.LogException(exception); } while (!cancellationToken.IsCancellationRequested) { try { var concurrentConnectonTest = new ConcurrentConnectionTest(); var concurrentConnectonTestSetup = new TestSetup(logger, brokerIp, concurrentConnectonTest, numberOfThreads); concurrentConnectonTestSetup.RunTest(int.MaxValue, new TimeSpan(0, 60, 0), new TimeSpan(0, 0, 3), new TimeSpan(0, 0, 3), new TimeSpan(0, 0, 30), new TimeSpan(0, 1, 0)); } catch (Exception exception) { logger.LogEvent("Incomplete", "Completed test using " + numberOfThreads + " threads"); logger.LogException(exception); } await Task.Delay(new TimeSpan(0, 1, 0)); GC.Collect(); GC.WaitForPendingFinalizers(); GC.WaitForFullGCComplete(); GC.Collect(); } }