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(() => { //执行代码 });