#regionDelegate callbacksStatic voidDelegateTest () {Console.WriteLine ("Synchronous Invocation"); Subdelegate Subdel=Sub; varresult = Subdel.invoke (3,4); Console.WriteLine ("continue to"); Console.WriteLine (result); Console.readkey (); Console.WriteLine ("Asynchronous Invocation"); Subdelegate sub1=Newsubdelegate (Sub); IAsyncResult RESULT1= Sub1. BeginInvoke (2,3,NULL,NULL); Console.WriteLine ("Go on"); Console.WriteLine (sub1. EndInvoke (RESULT1)); Console.readkey (); Console.WriteLine ("Asynchronous Callbacks"); Subdelegate Sub2=Newsubdelegate (Sub); IAsyncResult result2= Sub2. BeginInvoke (5,6,NewAsyncCallback (CallBack),NULL); Console.WriteLine ("Go on"); Console.readkey (); } Delegate intSubdelegate (intAintb); Static intSub (intAintb) {Console.WriteLine ("Start Calculation"); Thread.Sleep ( the); Console.WriteLine ("Settlement Complete"); returnAb; } Static voidCallBack (IAsyncResult result) {Subdelegate Sub=( subdelegate) ((AsyncResult) result). AsyncDelegate; Console.WriteLine (Sub. EndInvoke (result)); } #endregion
C # delegate invocation (synchronous call, asynchronous call, asynchronous callback)