示例#1
0
        public static async Task RunSingleTask()
        {
            PlaygroundUtils.Start("Single");

            try
            {
                // throws
                await RunAsync(0);
            }
            catch (Exception e)
            {
                PlaygroundUtils.PrintExceptionInfo(e);
            }
        }
示例#2
0
        public static Task RunSingleVoidTask()
        {
            PlaygroundUtils.Start("Single-Void");

            try
            {
                // throws
                FailingService.ThrowVoid();
            }
            catch (Exception e)
            {
                PlaygroundUtils.PrintExceptionInfo(e);
            }

            return(Task.CompletedTask);
        }
示例#3
0
        public static async Task RunMultipleTasks()
        {
            PlaygroundUtils.Start("Multiple");

            try
            {
                // throws exception with ms=50
                var task1 = FailingService.ThrowAfter(10);
                var task2 = FailingService.ThrowAfter(50);

                await task2;
                await task1;
            }
            catch (Exception e)
            {
                PlaygroundUtils.PrintExceptionInfo(e);
            }
        }
示例#4
0
        public static async Task RunWhenAll()
        {
            PlaygroundUtils.Start("When-All");

            try
            {
                var taskList = new[]
                {
                    Task.Run(() => RunAsync(1)),
                    Task.Run(() => RunAsync(2)),
                    Task.Run(() => RunAsync(3)),
                };

                // throws exception with i=1
                await Task.WhenAll(taskList);
            }
            catch (Exception e)
            {
                PlaygroundUtils.PrintExceptionInfo(e);
            }
        }
        public static async Task RunAggregateNonAwaited()
        {
            PlaygroundUtils.Start("Aggregate Non-Awaited");

            Task whenAll = null;

            try
            {
                var tasks = new[]
                {
                    FailingService.ThrowSomething("instant awaited"),
                    FailingService.ThrowAfter(120)
                };

                whenAll = Task.WhenAll(tasks);
                await whenAll;
            }
            catch (Exception e)
            {
                HandleAggregateTaskException(whenAll, e);
            }
        }