Beispiel #1
0
        static void MyCallBackMethod(IAsyncResult ar)
        {
            AsyncResult   asyncResult = (AsyncResult)ar;
            MathOperation op          = (MathOperation)asyncResult.AsyncDelegate;

            double result = op.EndInvoke(ar);

            Console.WriteLine("Result: {0}", result);
        }
Beispiel #2
0
        void myCallBackMath(IAsyncResult ar)
        {
            //IAsyncResult代表非同步的作業狀態
            //AsyncState取得使用者定義物件
            //AsyncResult封裝委派上面非同步作業的結果
            //AsyncDelegate取得非同步呼叫已叫用的委派物件。回傳:非同步呼叫已叫用委派物件

            object        hello       = ar.AsyncState;                            //ar的AsyncState方法結束會回傳一個 hello物件變數//像是object HelloTest = null;object helloa = HelloTest;
            AsyncResult   asyncResult = (AsyncResult)ar;                          //hello物件變數就是AsyncResult的物件變數
            MathOperation op          = (MathOperation)asyncResult.AsyncDelegate; //AsyncDelegate回傳asyncResult物件變數
            double        rs          = op.EndInvoke(ar);                         //EndInvoke呼叫完畢後將傳入數值的結果回傳回來

            Console.WriteLine("回呼回傳值: {0}, 資料引數: {1}", rs, hello);
        }