Guest User

Untitled

a guest
Jan 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. Task T = Task.Run(() => { });
  2.  
  3. /// <summary>
  4. /// Starts the new <see cref="Task"/> from <paramref name="function"/> on the Default(usually ThreadPool) task scheduler (not on the TaskScheduler.Current).
  5. /// It is a 4.0 method nearly analogous to 4.5 Task.Run.
  6. /// </summary>
  7. /// <typeparam name="T">The type of the return value.</typeparam>
  8. /// <param name="factory">The factory to start from.</param>
  9. /// <param name="function">The function to execute.</param>
  10. /// <returns>The task representing the execution of the <paramref name="function"/>.</returns>
  11. public static Task<T> StartNewOnDefaultScheduler<T>(this TaskFactory factory, Func<T> function)
  12. {
  13. Contract.Requires(factory != null);
  14. Contract.Requires(function != null);
  15.  
  16. return factory
  17. .StartNew(
  18. function,
  19. cancellationToken: CancellationToken.None,
  20. creationOptions: TaskCreationOptions.None,
  21. scheduler: TaskScheduler.Default);
  22. }
  23.  
  24. Task
  25. .Factory
  26. .StartNewOnDefaultScheduler(() =>
  27. result);
Add Comment
Please, Sign In to add comment