What happens if an unhandled exception is raised in a multicast delegate? : Delegate Async « Language Basics « 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() {
        try {
            DelegateClass del = MethodA;
            IAsyncResult ar = del.BeginInvoke(null, null);
            del.EndInvoke(ar);
        } catch (Exception except) {
            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.Async Delegate Invocation
2.Async Delegates Callback
3.delegate BeginInvoke of IAsyncResult