Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are few different things going on:</p> <p>First, if you call <code>Wait()</code> on a faulted <code>Task</code>, it will <em>always</em> throw an exception, no matter if you already observed it or not. In your code, this means that if you call <code>task.Wait()</code> from <code>Main()</code>, the whole application will crash, because you have unhandled exception in <code>Main()</code>.</p> <p>Second, <a href="http://blogs.msdn.com/b/pfxteam/archive/2011/09/28/10217876.aspx" rel="noreferrer">the behavior of unhandled exceptions in <code>Task</code>s changed in .Net 4.5</a> and they will no longer cause the application to crash. The article also describes how to switch back to the original behavior. And if you have .Net 4.5 installed, this applies also to applications targeting .Net 4.0 (e.g. those built using VS 2010).</p> <p>Third, with the .net 4.0 behavior, the application crashes <em>when the <code>Task</code> is garbage collected</em> (assuming the exception wasn't observed before that point). This is because before that, there is still a chance your code will observe that exception.</p> <p>So, the following code crashes the application (assuming you enabled the .Net 4.0 behavior if you have .Net 4.5 installed):</p> <pre><code>static void Main() { Task.Factory.StartNew(() =&gt; { throw new Exception(); }); // give the Task some time to run Thread.Sleep(100); GC.Collect(); } </code></pre> <p>Your code didn't crash, because the GC didn't have chance to run before the application exited normally.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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