Пример #1
0
        private static bool CrashIfCanceledWithDifferentToken(OperationCanceledException exception, CancellationToken cancellationToken)
        {
            if (exception.CancellationToken != cancellationToken)
            {
                ExceptionHelpers.Crash(exception);
            }

            return(false);
        }
Пример #2
0
        public static Task <TResult> SafeStartNewFromAsync <TResult>(
            this TaskFactory factory,
            Func <Task <TResult> > funcAsync,
            CancellationToken cancellationToken,
            TaskCreationOptions creationOptions,
            TaskScheduler scheduler)
        {
            // The one and only place we can call StartNew<>().
            var task = factory.StartNew(funcAsync, cancellationToken, creationOptions, scheduler).Unwrap();

            // make it crash if exception has thrown
            task.SafeContinueWith(t => ExceptionHelpers.Crash(t.Exception),
                                  CancellationToken.None,
                                  TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously,
                                  TaskScheduler.Default);

            return(task);
        }