Peter Duniho <Np*********@nnowslpianmk.comwrote:
On Mon, 02 Apr 2007 09:47:59 -0700, james <ja********@gmail.comwrote:
When I compile and run this code outside of Visual Studio no exception
is reported to the console and the program continues to run.
As far as I know, that's "by design". That is, since you have no
exception handler in the new thread, there's no code to detect the
exception and so the thread just exits (abnormally) without notice.
The fact that it's running from a timer is significant though. In .NET
2.0, if a new "plain" thread throws an exception, it will abort the
program. Try this:
using System;
class Program
{
static void Main(string[] args)
{
new System.Threading.Thread(Foo).Start();
Console.ReadLine();
}
static void Foo()
{
throw new Exception();
}
}
In .NET 1.1 (IIRC) this wouldn't stop the program, but in .NET 2.0 it
does. From a *very* quick bit of experimentation, it looks like
threadpool threads throwing exceptions doesn't cause the program to
terminate, and System.Timers.Timer runs on thread pool threads. That
could be an over-simplification though...
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too