Task.Factory.StartNew() vs. TaskEx.Run()
Asked Answered
W

2

13

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 ?

Wheatear answered 25/5, 2011 at 11:20 Comment(1)
TaskEx.Run is now Task.Run in the .NET 4.5 RTM framework TaskEx was needed as a temporary measureOrfield
B
14

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. :)

Befall answered 25/5, 2011 at 11:31 Comment(2)
It did :-) I wish the documentation for this mentioned it was a shorthand for Task.Factory.StartNew - msdn.microsoft.com/en-us/library/hh195051.aspxOrfield
This is just partially correct. Blog post talks about what to expect from Task.Run. Specially in the scenario where the action returns Task<TResult>, Task.Factory.StartNew would return a Task<Task<TResult> requiring an Unwrap to get the inner task where as Task.Run would return a Task<TResult> with an implicit unwrap.Outfit
T
6

Stephen Toub covered it in his article. They are the same, one being shorthand for the other.

Trawl answered 17/1, 2013 at 17:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.