public static int Run()
        {
            var mainTask = Task.Run(TaskActions.MainTaskAction);

            var child = mainTask
                        .ContinueWith(_ => TaskActions.ContinuationTaskAction());

            child.GetAwaiter().GetResult();

            return(0);
        }
        public static int Run()
        {
            var cts = new CancellationTokenSource();

            var token    = cts.Token;
            var mainTask = Task.Run(() => TaskActions.MainTaskAction(token), token);

            Thread.Sleep(700);
            cts.Cancel();

            mainTask
            .ContinueWith(
                _ => TaskActions.ContinuationTaskAction(),
                TaskContinuationOptions.NotOnRanToCompletion);

            mainTask.GetAwaiter().GetResult();

            return(0);
        }
예제 #3
0
        public static int Run()
        {
            var cts = new CancellationTokenSource();

            var token    = cts.Token;
            var mainTask = Task.Run(() => TaskActions.MainTaskAction(token), token);

            Thread.Sleep(500);
            cts.Cancel();

            mainTask
            .ContinueWith(
                _ => TaskActions.ContinuationTaskAction(),
                TaskContinuationOptions.OnlyOnCanceled |
                TaskContinuationOptions.RunContinuationsAsynchronously);

            mainTask.GetAwaiter().GetResult();

            return(0);
        }