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 ?

Yaron Levi
  • 12,535
  • 16
  • 69
  • 118

2 Answers2

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

Bruno Brant
  • 8,226
  • 7
  • 45
  • 90
aL3891
  • 6,205
  • 3
  • 33
  • 37
  • 2
    It did :-) I wish the documentation for this mentioned it was a shorthand for Task.Factory.StartNew - http://msdn.microsoft.com/en-us/library/hh195051.aspx – Simon_Weaver Sep 09 '12 at 07:22
  • 8
    This is just partially correct. [Blog post](http://blogs.msdn.com/b/pfxteam/archive/2011/10/24/10229468.aspx) talks about what to expect from `Task.Run`. Specially in the scenario where the action returns `Task`, `Task.Factory.StartNew` would return a `Task` requiring an `Unwrap` to get the inner task where as `Task.Run` would return a `Task` with an implicit unwrap. – Anupam Aug 16 '13 at 17:26
6

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

Bruno Brant
  • 8,226
  • 7
  • 45
  • 90