using System.Threading.Tasks;
namespace BeginEndInvokeTest
public static void Main(string[] args)
var caller = new AsyncDemo.AsyncMethodCaller(AsyncDemo.Test);
var ar = caller.BeginInvoke(3000, AsyncCallback, caller);
static void AsyncCallback(IAsyncResult ar)
var caller = (AsyncDemo.AsyncMethodCaller) ar.AsyncState;
Console.WriteLine("No exception was thrown");
Console.WriteLine("Exception encountered");
public static string Test(int callDuration)
Console.WriteLine("Test method begins");
Thread.Sleep(callDuration);
throw new Exception("Testing");
public delegate string AsyncMethodCaller(int callDuration);