I just learned that Microsoft changed the way unhandled exceptions in Threads are propogated in .Net 2.0 vs the way they worked in 1.1.  With 2.0 any unhandled exceptions in a thread will not only cause that thread to exit, but will also be bubbled up to the thread that started the offending thread.  Overall, I think this is a good thing, since not only will it force people to handle exceptions within their thread code, but it will also eliminate the problem of processes mysteriously stopping if there is an unhandled exception on a thread.  It will, however, cause some serious grief for any developers not expecting that sort of behavior.  I’m sure I’m not the only one who has seen less than steller multi-threaded programming tactics in applications which should be better behaived (heck, I’ve done my share of shoddy thread handling in the past).

The one exception to this, of course, is the ThreadAbortException, which understandably, only effects the thread it is raised on.  Granted using Thread.Abort, or raising a ThreadAbortException is considered a brute-force approach, so it shouldn’t be happening anyway….

It just goes to show that there are always little surprises waiting around the corner.  I’ve been looking at least casually at .Net 2.0 since Beta 2, and I even read through the “What’s New” for C# 2.0 to see if I missed anything.  Somehow I managed not to notice Implicit Delegate Assignment (or at least that’s what I’m calling it).

It is now possible to assign a delegate using just the Class and Method name…you no longer have to create a new instance of the delegate type.  Not a huge thing, I know, but for those of us who are easily impressed it’s, well, impressive.

Here’s the skinny in code language:

public class SomeClass
{
    public event EventHandler MyEvent;
}

public class SomeOtherClass
{
    SomeClass _class; 
    public SomeOtherClass()
    {
        _class = new SomeClass();   
        // Old Way
        _class.MyEvent += new EventHandler(this.MyHandler);
        
       // New Way
       _class.MyEvent += this.MyHandler;
    }

    public void EventHandler(object sender, EventArgs args)
    {
        // Handler Code
    }
}