コード例 #1
0
        async static Task p606_LaunchFoo_and_TimedCancel()
        {
            var token = new MyCancellationToken();

            var tskConti = Task.Delay(2000).ContinueWith(ant =>
                                                         token.Cancel()
                                                         ); // Tell it to cancel in two seconds.

            await p606_FooAsync(token);
        }
コード例 #2
0
        async static Task p606_FooAsync(MyCancellationToken cancellationToken)
        {
            Thread.Sleep(200); // Chj: to tear apart 1000ms boundary

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(i);
                await Task.Delay(1000);

                cancellationToken.ThrowIfCancellationRequested();
            }
        }