Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Task T = Task.Run(() => { });
- /// <summary>
- /// Starts the new <see cref="Task"/> from <paramref name="function"/> on the Default(usually ThreadPool) task scheduler (not on the TaskScheduler.Current).
- /// It is a 4.0 method nearly analogous to 4.5 Task.Run.
- /// </summary>
- /// <typeparam name="T">The type of the return value.</typeparam>
- /// <param name="factory">The factory to start from.</param>
- /// <param name="function">The function to execute.</param>
- /// <returns>The task representing the execution of the <paramref name="function"/>.</returns>
- public static Task<T> StartNewOnDefaultScheduler<T>(this TaskFactory factory, Func<T> function)
- {
- Contract.Requires(factory != null);
- Contract.Requires(function != null);
- return factory
- .StartNew(
- function,
- cancellationToken: CancellationToken.None,
- creationOptions: TaskCreationOptions.None,
- scheduler: TaskScheduler.Default);
- }
- Task
- .Factory
- .StartNewOnDefaultScheduler(() =>
- result);
Add Comment
Please, Sign In to add comment