public void TaskExtensions_TaskOfTEnsureCompleted_NotCompletedInSyncContext() { using SingleThreadedSynchronizationContext syncContext = new SingleThreadedSynchronizationContext(); var tcs = new TaskCompletionSource <int>(); syncContext.Post(t => { Assert.Catch <InvalidOperationException>(() => tcs.Task.EnsureCompleted()); }, null); }
public void TestPost() { var postComplete = false; var sync = new SingleThreadedSynchronizationContext(); var latch = new ManualResetEvent(false); sync.Post(state => { postComplete = true; latch.Set(); }, null); Assert.IsFalse(postComplete); latch.WaitOne(); Assert.IsTrue(postComplete); }