I build a small sample application in .Net 4.0 to test some task exception handling. I write the code below
Task.Factory.StartNew(() =>
{
throw new Exception("Exception");
}
Thread.Sleep(100);
GC.Collect();
GC.WaitForPendingFinalizers();
I expected, as my application is net 4.0, that I will get an unhandled exception but nothing happens. I see in the post UnobservedTaskException is not killing the process that even if your application is .Net 4.0 if you have Net framework 4.5 installed, it will run on this later.
Indeed when I add :
<runtime>
<ThrowUnobservedTaskExceptions enabled="true"/>
</runtime>
The exception is thrown as with application in 4.5
Can someone explain what is the general principle about application version and installed framework version?