2 using System
.Threading
;
3 using System
.Runtime
.InteropServices
;
6 delegate int SimpleDelegate (int a
);
9 Console
.WriteLine ("Test.F from delegate: " + a
);
14 static void async_callback (IAsyncResult ar
)
16 Console
.WriteLine ("Async Callback " + ar
.AsyncState
);
20 SimpleDelegate d
= new SimpleDelegate (F
);
21 AsyncCallback ac
= new AsyncCallback (async_callback
);
22 string state1
= "STATE1";
23 string state2
= "STATE2";
24 string state3
= "STATE3";
25 string state4
= "STATE4";
28 IAsyncResult ar1
= d
.BeginInvoke (1, ac
, state1
);
29 IAsyncResult ar2
= d
.BeginInvoke (2, ac
, state2
);
30 IAsyncResult ar3
= d
.BeginInvoke (3, ac
, state3
);
31 IAsyncResult ar4
= d
.BeginInvoke (4, ac
, state4
);
33 int res
= d
.EndInvoke (ar1
);
35 Console
.WriteLine ("Result = " + res
);
39 } catch (InvalidOperationException
) {
40 Console
.WriteLine ("cant execute EndInvoke twice ... OK");
43 ar1
.AsyncWaitHandle
.WaitOne ();
44 if (ar1
.IsCompleted
) fin
++;
45 Console
.WriteLine ("completed1: " + ar1
.IsCompleted
);
46 ar2
.AsyncWaitHandle
.WaitOne ();
47 if (ar2
.IsCompleted
) fin
++;
48 Console
.WriteLine ("completed2: " + ar2
.IsCompleted
);
49 ar3
.AsyncWaitHandle
.WaitOne ();
50 if (ar3
.IsCompleted
) fin
++;
51 Console
.WriteLine ("completed3: " + ar3
.IsCompleted
);
52 ar4
.AsyncWaitHandle
.WaitOne ();
53 if (ar4
.IsCompleted
) fin
++;
54 Console
.WriteLine ("completed4: " + ar4
.IsCompleted
);