Пример #1
0
        private static void GetReturnValue(IAsyncResult res)
        {
            AsyncResult    ar     = (AsyncResult)res;
            int            number = (int)ar.AsyncState;
            GetNumDelegate gnd    = (GetNumDelegate)ar.AsyncDelegate;

            MessageBox.Show(gnd.EndInvoke(res).ToString(), "Called GetNum_1 method with " + number);
        }
Пример #2
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            int number = 10000;
            //Gọi phương thức GetNum_1 theo cơ chế không đồng bộ
            GetNumDelegate gnd = new GetNumDelegate(GetNum_1);
            AsyncCallback  acb = new AsyncCallback(GetReturnValue);
            IAsyncResult   res = gnd.BeginInvoke(acb, number);

            //Gọi phương thức GetNum_2
            MessageBox.Show(GetNum_2().ToString(), "Called GetNum_2 method !");
        }