static int Main() { SimpleDelegate d = new SimpleDelegate(F); AsyncCallback ac = new AsyncCallback(async_callback); string state1 = "STATE1"; string state2 = "STATE2"; string state3 = "STATE3"; string state4 = "STATE4"; int fin = 0; IAsyncResult ar1 = d.BeginInvoke(1, ac, state1); IAsyncResult ar2 = d.BeginInvoke(2, ac, state2); IAsyncResult ar3 = d.BeginInvoke(3, ac, state3); IAsyncResult ar4 = d.BeginInvoke(4, ac, state4); int res = d.EndInvoke(ar1); Console.WriteLine("Result = " + res); try { d.EndInvoke(ar1); } catch (InvalidOperationException) { Console.WriteLine("cant execute EndInvoke twice ... OK"); } ar1.AsyncWaitHandle.WaitOne(); if (ar1.IsCompleted) { fin++; } Console.WriteLine("completed1: " + ar1.IsCompleted); ar2.AsyncWaitHandle.WaitOne(); if (ar2.IsCompleted) { fin++; } Console.WriteLine("completed2: " + ar2.IsCompleted); ar3.AsyncWaitHandle.WaitOne(); if (ar3.IsCompleted) { fin++; } Console.WriteLine("completed3: " + ar3.IsCompleted); ar4.AsyncWaitHandle.WaitOne(); if (ar4.IsCompleted) { fin++; } Console.WriteLine("completed4: " + ar4.IsCompleted); if (fin != 4) { return(1); } return(0); }
static int Main () { SimpleDelegate d1 = new SimpleDelegate (Method); SimpleDelegate d2 = new SimpleDelegate (Method); AsyncCallback ac = new AsyncCallback (Callback); IAsyncResult ar1 = d1.BeginInvoke (1, ac, null); IAsyncResult ar2 = d2.BeginInvoke (2, ac, null); try { d1.EndInvoke (ar2); return 1; } catch (InvalidOperationException) { // expected } try { d2.EndInvoke (ar1); return 2; } catch (InvalidOperationException) { // expected } if (1 != d1.EndInvoke (ar1)) return 3; if (2 != d2.EndInvoke (ar2)) return 4; return 0; }
static int Main() { SimpleDelegate d1 = new SimpleDelegate(Method); SimpleDelegate d2 = new SimpleDelegate(Method); AsyncCallback ac = new AsyncCallback(Callback); IAsyncResult ar1 = d1.BeginInvoke(1, ac, null); IAsyncResult ar2 = d2.BeginInvoke(2, ac, null); try { d1.EndInvoke(ar2); return(1); } catch (InvalidOperationException) { // expected } try { d2.EndInvoke(ar1); return(2); } catch (InvalidOperationException) { // expected } if (1 != d1.EndInvoke(ar1)) { return(3); } if (2 != d2.EndInvoke(ar2)) { return(4); } return(0); }
static int Main() { SimpleDelegate d = new SimpleDelegate(async_func_throws); AsyncCallback ac = new AsyncCallback(async_callback); string state1 = "STATE1"; // Call delegate via ThreadPool and check that the exception is rethrown correctly IAsyncResult ar1 = d.BeginInvoke(1, ac, state1); while (cb_state == 0) { Thread.Sleep(0); } try { d.EndInvoke(ar1); Console.WriteLine("NO EXCEPTION"); return(1); } catch (AsyncException) { Console.WriteLine("received exception ... OK"); return(0); } catch (Exception e) { Console.WriteLine("wrong exception {0}", e); return(3); } }
static int Main () { SimpleDelegate d = new SimpleDelegate (F); AsyncCallback ac = new AsyncCallback (async_callback); string state1 = "STATE1"; int res = 0; IAsyncResult ar1 = d.BeginInvoke (1, ac, state1); ar1.AsyncWaitHandle.WaitOne (); try { res = d.EndInvoke (ar1); } catch (NotImplementedException) { res = 1; Console.WriteLine ("received exception ... OK"); } while (cb_state == 0) Thread.Sleep (0); if (cb_state != 1) return 1; if (res != 1) return 2; return 0; }
static int Main() { SimpleDelegate d = new SimpleDelegate(F); AsyncCallback ac = new AsyncCallback(async_callback); string state1 = "STATE1"; int res = 0; IAsyncResult ar1 = d.BeginInvoke(1, ac, state1); ar1.AsyncWaitHandle.WaitOne(); try { res = d.EndInvoke(ar1); while (cb_state == 0) { Thread.Sleep(0); } } catch (NotImplementedException) { res = 1; Console.WriteLine("received exception ... OK"); } if (cb_state != 1) { return(1); } if (res != 1) { return(2); } return(0); }
static int Main () { SimpleDelegate d = new SimpleDelegate (F); AsyncCallback ac = new AsyncCallback (async_callback); string state1 = "STATE1"; string state2 = "STATE2"; string state3 = "STATE3"; string state4 = "STATE4"; int fin = 0; IAsyncResult ar1 = d.BeginInvoke (1, ac, state1); IAsyncResult ar2 = d.BeginInvoke (2, ac, state2); IAsyncResult ar3 = d.BeginInvoke (3, ac, state3); IAsyncResult ar4 = d.BeginInvoke (4, ac, state4); int res = d.EndInvoke (ar1); Console.WriteLine ("Result = " + res); try { d.EndInvoke (ar1); } catch (InvalidOperationException) { Console.WriteLine ("cant execute EndInvoke twice ... OK"); } ar1.AsyncWaitHandle.WaitOne (); if (ar1.IsCompleted) fin++; Console.WriteLine ("completed1: " + ar1.IsCompleted); ar2.AsyncWaitHandle.WaitOne (); if (ar2.IsCompleted) fin++; Console.WriteLine ("completed2: " + ar2.IsCompleted); ar3.AsyncWaitHandle.WaitOne (); if (ar3.IsCompleted) fin++; Console.WriteLine ("completed3: " + ar3.IsCompleted); ar4.AsyncWaitHandle.WaitOne (); if (ar4.IsCompleted) fin++; Console.WriteLine ("completed4: " + ar4.IsCompleted); if (fin != 4) return 1; return 0; }
static int Main () { SimpleDelegate d = new SimpleDelegate (F); AsyncCallback ac = new AsyncCallback (async_callback); string state1 = "STATE1"; int res = 0; // Call delegate via ThreadPool and check that the exception is rethrown correctly IAsyncResult ar1 = d.BeginInvoke (1, ac, state1); while (cb_state == 0) Thread.Sleep (0); try { res = d.EndInvoke (ar1); Console.WriteLine ("NO EXCEPTION"); return 1; } catch (NotImplementedException) { Console.WriteLine ("received exception ... OK"); } return 0; }