Task.Factory.StartNew() basically receives an Action and returns a Task. In The Async CTP we have TaskEx.Run() which also receives an Action and returns a Task. They seem to do that same thing. Why TaskEx.Run() was introduced ?
StartNew(Action<Object>, Object, CancellationToken, TaskCreationOptions, TaskScheduler) Creates and starts a task for the specified action delegate, state, cancellation token, creation options and task scheduler.
NET code does not mean there are separate new threads involved. Generally when using Task. Run() or similar constructs, a task runs on a separate thread (mostly a managed thread-pool one), managed by the . NET CLR.
The TaskFactory class allows you to do the following: Create a task and start it immediately by calling the StartNew method. Starting with . NET Framework 4.5, the Task.
Inside DoComplexCalculusAsync(), Task. Run uses another new thread from thread pool to do the heavy calculations in the background. Thus the thread pool has to deal with unexpectedly loosing one thread from the pool.
Anders Hejlsberg talked about that briefly in an interview on Channel9. Apparently, Task.Run
is just a shorthand for Task.Factory.StartNew
. Its still early CTP days so we're unsure that Task.Run
will make it int. I personally hope it won't because it's kind of redundant. :)
Stephen Toub covered it in his article. They are the same, one being shorthand for the other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With