예제 #1
0
        private void MainFunction()
        {
            //第二步:声明这个代理类型
            OurFunctionDelegate hander = new OurFunctionDelegate(OurFunction);

            //第三步:调用BgeinInvoke方法,同时传入一个回调函数
            hander.BeginInvoke("p1", "p2", "p3", AsyncCallBack, hander);
        }
예제 #2
0
        //第四步:定义一个回调函数
        private void AsyncCallBack(IAsyncResult result)
        {
            OurFunctionDelegate hander = (OurFunctionDelegate)result.AsyncState;

            try
            {
                //函数异步执行完成,会进入这个函数,调用EndInvoke方法可以得到结果,如有异常,也会在这里抛出
                UserInfo info = hander.EndInvoke(result);
            }
            catch (Exception)
            {
                //处理异步操作的异常,当然,这里的异常应该是ArrgregateException。
            }
        }