Async异步委托

    /// <summary>
    /// 异步委托
    /// </summary>
    public delegate void AsyncHandler();

    public static class AsyncHelper
    {
        public static void AsyncResult(AsyncHandler asyncHandler)
        {
            IAsyncResult asyncResult = asyncHandler.BeginInvoke(new AsyncCallback(endInvoke), asyncHandler);
        }

        //异步回调
        private static void endInvoke(IAsyncResult ar)
        {
            AsyncHandler invoke = (AsyncHandler)ar.AsyncState;
            invoke.EndInvoke(ar);
        }


    }

 

代码调用:

 //异步执行
                        AsyncHelper.AsyncResult(() =>
                        {
                              //执行代码
      
                        });    

 

posted @ 2015-10-12 13:52  dragon.net  阅读(366)  评论(0编辑  收藏  举报