sger6218
sger6218

Reputation: 397

Can a .NET managed thread 'vanish' without killing the process?

I have recently encountered a situation where a .NET thread running as part of a Microsoft Outlook Addin (potentially relevant?) appears to have 'vanished'.

We have an object that wraps the System.Threading.Thread and sets a 'stopped' flag as soon as the underlying thread finishes running its callback.

The System.Threading thread in question was an MTA thread and had the Background property set to true. We are not operating in 'legacy' unhandled thread exceptions mode. An unhandled exception on a background thread can and does kill the program.

The thread in question operates a task queue. At some point while Outlook was running I noticed the task queue was not processing. I attached a debugger and noticed the thread was no longer alive. The 'stopped' flag had not been set, indicating that the thread callback did not finish executing. The wrapper object does not catch any exceptions.

It may be relevant that the thread in question does perform a tiny bit of COM interop. It checks a boolean property exposed by COM.

Irrespective of that - I would have expected that if the background thread threw an exception, the hosting process would have crashed, reporting an unhandled exception.

Are there any scenarios anyone knows of that would allow a thread to die or otherwise vanish without bringing down the process?

This article notes there are three circumstances in which .NET will kill the thread but allow the program to continue: http://msdn.microsoft.com/en-us/library/ms228965.aspx

I know for certain that the first two points do not apply here. I wonder if there is anything in the 3rd point that might be relevant? I have searched online, but cannot find any other clue as to what the referenced 'internal exceptions' might be.

Upvotes: 1

Views: 133

Answers (1)

Andrew Barber
Andrew Barber

Reputation: 40160

Internal exceptions just means an exception was thrown in the thread's code. That would end the thread.

Upvotes: 2

Related Questions