public static void Async <TReturn>(Func <TReturn> operation, Action <Exception, TReturn> callback) { EventLoop.Pend(() => { try { var result = operation(); callback(null, result); } catch (Exception ex) { EventLoop.Pend(() => callback(ex, default(TReturn))); throw; } }); }
private void Work(Task incomingTask) { if (StopHandle.WaitOne(0)) { return; } var evt = EventLoop.NextEvent(); if (evt != null) { Idle = false; _worker = incomingTask.ContinueWith(w2 => evt()); _worker.ContinueWith(Work); } else { Idle = true; } incomingTask.Dispose(); }
public static void Async(Action operation, Action <Exception> callback = null) { EventLoop.Pend(() => { try { operation(); if (callback != null) { EventLoop.Pend(() => callback(null)); } } catch (Exception ex) { if (callback != null) { EventLoop.Pend(() => callback(ex)); } } }); }