Task.Factory.StartNew with uncaught Exceptions kills w3wp?

6.4k views Asked by At

I just transitioned some of my website's code from using QueueUserWorkItem to Task.Factory.StartNew

I have some bad code that threw an Exception and it ultimately shut down w3wp. Running IIS 7.5 on Windows Server 2008 R2, x64

                Task.Factory.StartNew(() =>
                {
                    MethodThatThrowsException();
                }

Application: w3wp.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.AggregateException Stack: at System.Threading.Tasks.TaskExceptionHolder.Finalize()

Exception: System.AggregateException

Message: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.

StackTrace: at System.Threading.Tasks.TaskExceptionHolder.Finalize()

InnerException: System.Data.SqlClient.SqlException

I would have assumed an exception would have generated an event log and NOT have killed w3wp. Is this a wrong assumption?

1

There are 1 answers

0
Lex Li On BEST ANSWER

Unhandled exceptions crash IIS worker process. This is by design. http://support.microsoft.com/kb/911816

Therefore, you should properly handle exceptions.