We use Tasks in our .Net 4 application (not available for asynchronous waiting), and sometimes they are used to start Fire and Forget operations, such as the following:
private void Test() { Task task = Task.Factory.StartNew(() => { throw new ApplicationException("Test"); }); }
We want this exception to crash the application without waiting for the task (since otherwise it makes no sense to have it in the task, at least in our scripts) and not waiting for the finalizer, since we want to terminate the application when an unexpected error occurs so that avoid state corruption (we maintain the state present when an exception occurs).
I suppose that somehow we have to work with the continuation task, but this puts the continuation code in another task that will not cause the application to crash, so I am blocked here.
Any help would be much appreciated
Edit: if you switch to ThreadPool, the result will be expected. The following code causes the application to crash:
ThreadPool.QueueUserWorkItem((c) => { throw new ApplicationException("Test"); });
source share