コード例 #1
0
 // <summary>
 // Adapts any action into a Task (returning AsyncVoid, so that it's usable with Task{T} extension methods).
 // </summary>
 static Task <AsyncVoid> ToAsyncVoidTask(Action action)
 {
     return(TaskHelpers.RunSynchronously(() => {
         action();
         return DefaultCompleted;
     }));
 }
コード例 #2
0
        public void RunSynchronously_Executes_Action()
        {
            bool wasRun = false;
            Task t      = TaskHelpers.RunSynchronously(() => { wasRun = true; });

            t.WaitUntilCompleted();
            Assert.True(wasRun);
        }
コード例 #3
0
        public void RunSynchronously_Cancels()
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            cts.Cancel();

            Task t = TaskHelpers.RunSynchronously(() => { throw new InvalidOperationException(); }, cts.Token);

            Assert.Throws <TaskCanceledException>(() => t.Wait());
        }
コード例 #4
0
        public void RunSynchronously_Captures_Exception_In_AggregateException()
        {
            Task t = TaskHelpers.RunSynchronously(() => { throw new InvalidOperationException(); });

            Assert.Throws <InvalidOperationException>(() => t.Wait());
        }