Reputation: 1417
I have a thread pool and I use a library that if certain conditions are met to throw an exception. My question is if this runs out of the IDE, will the thread come to an halt or will the whole entire program come to a halt?
Upvotes: 2
Views: 1705
Reputation: 48949
So lets review what you have:
TheadPool
thread.try-catch
block.Now we can easily test this with the following code. Pay careful attention to the observations below, especially the bold one, because they are interesting in the context of your question.
public static void Main()
{
ThreadPool.QueueUserWorkItem(
(state) =>
{
throw new InvalidOperationException();
}, null);
while (true)
{
Thread.Sleep(1000);
Console.WriteLine(DateTime.Now.ToString());
}
}
When running outside of the IDE you will observe the following.
When running inside the IDE1 you will observe the following.
1I tested this with Visual Studio 2010.
Upvotes: 3
Reputation: 38444
If the application is .Net 2+, an unhandled exception on a non-main thread will flatten the process.
You can configure this behavior using the app.config LegacyUnhandledExceptionPolicy
setting, but I wouldn't recommend this as it potentially masks serious bugs.
Update
If you wish to ignore the occasional timeout exception, consider placing your WebService call in a try\catch block and ignore the timeout exception:
try
{
//Call WebService
}
catch(System.Net.WebException ex)
{
//Ignore
}
Upvotes: 3
Reputation: 238086
When the debugger breaks a program, all threads come to a halt.
In the Debug -> Windows -> Threads
screen, you can see the threads. You can "freeze" a thread, which means it will stay halted if you continue running the program.
So it is possible to keep some threads halted even when the debugger runs. The opposite is not possible: no thread can run when the debugger is in break mode.
Upvotes: 1