public static void Execute(AsyncCall call, AsyncResult result) { try { result.Return = call(); } catch (Exception e) { result.LastException = e; result.Return = null; } finally { result.SignalWaitHandle(); if (result.Callback != null) { result.Callback(result); } } }
public static IAsyncResult BeginOperation(AsyncCall call, AsyncCallback callback, object state) { AsyncResult result = new AsyncResult(callback, state); new Thread(() => Execute(call, result)).Start(); return result; }