public static SimpleAsyncResult RunWithLock (object locker, SimpleAsyncFunc func, SimpleAsyncCallback callback) { return Run (inner => { bool running = func (inner); if (running) Monitor.Exit (locker); return running; }, inner => { if (inner.GotException) { if (inner.CompletedSynchronously) Monitor.Exit (locker); callback (inner); return; } try { if (!inner.CompletedSynchronously) Monitor.Enter (locker); callback (inner); } finally { Monitor.Exit (locker); } }); }
public static void RunWithLock(object locker, SimpleAsyncFunc func, SimpleAsyncCallback callback) { Run(inner => { bool running = func(inner); if (running) { Monitor.Exit(locker); } return(running); }, inner => { if (inner.GotException) { if (inner.CompletedSynchronously) { Monitor.Exit(locker); } callback(inner); return; } try { if (!inner.CompletedSynchronously) { Monitor.Enter(locker); } callback(inner); } finally { Monitor.Exit(locker); } }); }
public static void Run (SimpleAsyncFunc func, SimpleAsyncCallback callback) { var result = new SimpleAsyncResult (callback); try { if (!func (result)) result.SetCompleted (true); } catch (Exception ex) { result.SetCompleted (true, ex); } }
public static void Run(SimpleAsyncFunc func, SimpleAsyncCallback callback) { var result = new SimpleAsyncResult(callback); try { if (!func(result)) { result.SetCompleted(true); } } catch (Exception ex) { result.SetCompleted(true, ex); } }