What happens if an unhandled exception is raised in a multicast delegate? : IAsyncResult « Development Class « C# / C Sharp






What happens if an unhandled exception is raised in a multicast delegate?

 

using System;
using System.Threading;

public delegate void DelegateClass();

public class Starter {
    public static void Main() {
        Console.WriteLine("Running on primary thread");
        try {
            DelegateClass del = MethodA;
            IAsyncResult ar = del.BeginInvoke(null, null);
            del.EndInvoke(ar);
        } catch (Exception except) {
            Console.WriteLine("Running on primary thread");
            Console.WriteLine("Exception caught: " + except.Message);
        }
    }

    public static void MethodA() {
        if (Thread.CurrentThread.IsThreadPoolThread == true) {
            Console.WriteLine("Running on a thread pool thread");
        } else {
            Console.WriteLine("Running on primary thread");
        }
        throw new Exception("failure");
    }
}

 








Related examples in the same category

1.sample code for the EndInvoke method