[System] Tweak socket test
[mono-project.git] / mono / tests / async-with-cb-throws.cs
blob52791d4b9239b78169452287f805fd4b2725a4c6
1 using System;
2 using System.Threading;
3 using System.Runtime.InteropServices;
5 class AsyncException : Exception {}
7 class Tests
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);
16 return 10;
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);
28 cb_state = 1;
31 static int Main ()
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);
40 while (cb_state == 0)
41 Thread.Sleep (0);
43 try {
44 d.EndInvoke (ar1);
45 Console.WriteLine ("NO EXCEPTION");
46 return 1;
47 } catch (AsyncException) {
48 Console.WriteLine ("received exception ... OK");
49 return 0;
50 } catch (Exception e) {
51 Console.WriteLine ("wrong exception {0}", e);
52 return 3;