Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's the msdn <a href="http://msdn.microsoft.com/en-us/library/dd997417.aspx" rel="nofollow">documentation</a> on this.</p> <p>First of all, a "nested task" just means you start a new task within another task, like the following:</p> <pre><code>var outerTask = Task.Factory.StartNew( () =&gt; { var nestedTask = Task.Factory.StartNew( () =&gt; { Console.WriteLine("Inside nestedTask"); }); }); </code></pre> <p>What you probably meant was what is the difference between a "Nested Task" and "Child Task"</p> <p>A "child task" looks like this:</p> <pre><code>var parentTask = Task.Factory.StartNew( () =&gt; { var childTask = Task.Factory.StartNew( () =&gt; { Console.WriteLine("Inside childTask"); }, TaskCreationOptions.AttachedToParent ); }); </code></pre> <p>Child tasks will enforce certain synchronizations with the Parent task.</p> <p>Since, child tasks will always have higher synchronization overhead than independent nested tasks, it makes you wonder why you might want to use them at all.</p> <p>Sometimes you want to ensure synchronization of these tasks. You want the childTask to calculate something before the parent task completes. Other times, it might just make debugging easier, since you will have to deal with a little less non-determinism.</p> <p>Less non-determinism, may help you write and test your code faster.</p> <p>It is possible, though I'm not certain it is implemented this way, for child tasks to be injected on the same thread/core as the parent, especially when the parent is simply waiting for the child task. In this case you might be able to get added benefits of caching from the parent task in the child task.</p> <p>(It seems like a nice idea, but I don't think it's implemented that way yet, correct me if I'm wrong).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload