2 using System.Threading;
3 using System.Runtime.InteropServices;
5 class AsyncException : Exception {}
9 delegate int SimpleDelegate (int a);
11 static int cb_state = 0;
13 static int async_func (int a)
15 Console.WriteLine ("async_func from delegate: " + a);
19 static int async_func_throws (int a)
21 Console.WriteLine ("async_func_throws from delegate: " + a);
22 throw new AsyncException ();
25 static void async_callback (IAsyncResult ar)
27 Console.WriteLine ("Async Callback " + ar.AsyncState);
33 SimpleDelegate d = new SimpleDelegate (async_func_throws);
34 AsyncCallback ac = new AsyncCallback (async_callback);
35 string state1 = "STATE1";
37 // Call delegate via ThreadPool and check that the exception is rethrown correctly
38 IAsyncResult ar1 = d.BeginInvoke (1, ac, state1);
45 Console.WriteLine ("NO EXCEPTION");
47 } catch (AsyncException) {
48 Console.WriteLine ("received exception ... OK");
50 } catch (Exception e) {
51 Console.WriteLine ("wrong exception {0}", e);