C#耗时操作防界面卡死

1.1首先定义一个委托,该委托指向的方法就是要执行耗时长的操作

    public delegate string  mydelegate(int num);

1.2定义异步完成时回调的函数:

private void callBackMethod(IAsyncResult result)

        {

            /*由于已经在调用BeginInvoke传递的最后一个参数是回调委托

            所以可以从操作状态中获取*/

            mydelegate my = (mydelegate)result.AsyncState;

            //EndInvoke完成回调,并处理调用返回的结果

            string temp = my.EndInvoke(result);

            //处理返回的结果temp字符串

            MessageBox.Show("完成操作。" + temp);

}

 

posted on 2012-07-07 09:29  爱程序,爱生活  阅读(1506)  评论(1)    收藏  举报

导航