async Task Run() { lock (this) { if (cts != null) { return; } cts = new CancellationTokenSource(); } var assembly = typeof(Simple).Assembly; try { IsRunning = true; Status.StringValue = "Running ..."; var category = categories [SelectedCategory]; Delegate.Clear(); await AppDelegate.Instance.StartServer(); var suite = await TestSuite.Create(assembly); Status.StringValue = string.Format("Got testsuite: {0} fixtures, {1} tests.", suite.CountFixtures, suite.CountTests); lastStatus = DateTime.MinValue; suite.StatusMessageEvent += (sender, e) => UpdateStatus(e.Message); bool completed = false; var task = suite.Run(category, RepeatCount, cts.Token); while (!completed) { var ret = await Task.WhenAny(task, Task.Delay(statusInterval)); if (ret == task) { break; } CheckStatus(); } Delegate.SetResult(task.Result); Status.StringValue = "Done"; } catch (Exception ex) { Status.StringValue = string.Format("ERROR: {0}", ex.Message); Debug.Fail(string.Format("ERROR: {0}", ex)); } finally { IsRunning = false; cts.Dispose(); cts = null; } }
public virtual void Clear() { Delegate.Clear(); }