I am writing a multi-threaded application that relies on some third party DLLs. My problem is that when using an object from the third party library, if it raises an exception w
You can stop application crash by doing this:
AppDomain.CurrentDomain.UnhandledException += (sender, e2) =>
{
Thread.CurrentThread.Join();
};
But uncaught exception from 3d party components mean that components don't do their job properly. If you don't care if they don't do the job better don't use them.
The issue is probably that exceptions thrown on background threads are not caught once they bubble out of the thread proc.
This seems like a non-obvious duplicate of How to prevent an exception in a background thread from terminating an application?
One thing you might look at is the HandleProcessCorruptedStateExceptionsAttribute attribute.
I don't know if this is your problem or not, but I had to recently use this attribute on a method that was calling a function in a third party COM object. This attribute is new to .net 4.0. My basic understanding is that the 4.0 framework will by default not bubble up an exception thrown in certain situations where it feels the 3rd party exception may have introduced some instabilty. I think this pertains mostly to situations where the 3rd party component is unmanaged. I am not sure, but it resolved my issue.
The usage looks like this:
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptionsAttribute()]
private void ThirdPartyCall()
{
try
{
return Call3rdPartyFunction()
}
catch (Exception exInstantiate)
{
...
}
}
More information: http://msdn.microsoft.com/en-us/magazine/dd419661.aspx