public static Task <TResult> SafeStartNew <TResult>( this TaskFactory factory, Func <TResult> func, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler) { Func <TResult> wrapped = () => { try { return(func()); } catch (Exception e) if (ExceptionHelpers.CrashUnlessCanceled(e)) { throw ExceptionUtilities.Unreachable; } }; // The one and only place we can call StartNew<>(). return(factory.StartNew(wrapped, cancellationToken, creationOptions, scheduler)); } }