The following code seems as though it should swallow any type of exception in the try block, but the IIS worker process periodically dies and restarts because of an unhandled exception (marked with a comment.)
try
{
while (true)
{
DispatcherTask task = null;
lock (sync)
{
task = this.getTask();
if (task == null)
{
Monitor.Wait(sync);
continue;
}
}
lock (task)
{
task.Result = task.Task.DynamicInvoke(task.Params);
// ^ Delegate.DynamicInvoke(object[]) throws a TargetInvocationException
Monitor.PulseAll(task);
}
}
}
catch (Exception e)
{
}
UPDATE:
Definition of DispatcherTask
:
private class DispatcherTask
{
public Delegate Task;
public object[] Params;
public object Result;
}