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);
        }
Ejemplo n.º 2
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);
        }