public static async Task Test(int w, int h, TestContext testContext, Func <CliTestHarness, SpaceTimePanel, Task> test) { Exception stEx = null; var app = new CliTestHarness(testContext, w, h, true); app.SecondsBetweenKeyframes = DefaultTimeIncrement.TotalSeconds; app.InvokeNextCycle(async() => { var d = new TaskCompletionSource <bool>(); var spaceTimePanel = app.LayoutRoot.Add(new SpaceTimePanel(app.LayoutRoot.Width, app.LayoutRoot.Height)); spaceTimePanel.SpaceTime.Increment = DefaultTimeIncrement; var stTask = spaceTimePanel.SpaceTime.Start(); var justUpdated = false; spaceTimePanel.AfterUpdate.SubscribeForLifetime(() => justUpdated = true, app); app.AfterPaint.SubscribeForLifetime(() => { if (justUpdated) { app.RecordKeyFrame(); justUpdated = false; } }, app); spaceTimePanel.SpaceTime.InvokeNextCycle(async() => { spaceTimePanel.RealTimeViewing.Enabled = false; try { await test(app, spaceTimePanel); } catch (Exception ex) { stEx = ex; } await app.Paint(); d.SetResult(true); }); await d.Task; try { await stTask; }catch (Exception exc) { spaceTimePanel.SpaceTime.Stop(); d.SetResult(true); stEx = exc; } await spaceTimePanel.SpaceTime.YieldAsync(); await app.PaintAndRecordKeyFrameAsync(); spaceTimePanel.SpaceTime.Stop(); await app.PaintAndRecordKeyFrameAsync(); app.Stop(); }); await app.Start(); if (stEx != null) { app.Abandon(); Assert.Fail(stEx.ToString()); } else { app.PromoteToLKG(); } }