private void RunWorker(UnitTest test, CancellationToken cancelToken) { while (!cancelToken.IsCancellationRequested) { test.Execute(); } }
public async Task ExecuteTestAsync(UnitTest test, CancellationToken cancelToken) { TaskCompletionSource<object> executionCancelled = new TaskCompletionSource<object>(); Task testTask = Task.Run(() => test.Execute()); cancelToken.Register(() => executionCancelled.SetResult(null)); //if the execution is cancelled before the test is complete that test will continue running //however this should only occur when the execution has run to duration so we return to allow the process to exit await Task.WhenAny(testTask, executionCancelled.Task); }