public static DispatcherTimer StartAfter <T, R>( T arg, Func <T, Action <T, string, int>, R> doWork, Action <T, string, int> onProgress, Action <T, R> onComplete, Action <T, Exception> onError, TimeSpan duration) { var timer = new DispatcherTimer(duration, DispatcherPriority.Normal, new EventHandler((sender, e) => { var currentTimer = (sender as DispatcherTimer); currentTimer.Stop(); lock (_timerPool) { _timerPool.Remove(currentTimer); if (_timerPool.Count == 0) { _AllTimerFiredEvent.Set(); } } ParallelWork.StartNow <T, R>(arg, doWork, onProgress, onComplete, onError); }), Dispatcher.CurrentDispatcher); _AllTimerFiredEvent.Reset(); lock (_timerPool) _timerPool.Add(timer); timer.Start(); return(timer); }
public void Run() { ParallelWork.StartNow <object, object>(new object(), (o, progressCallback) => { this.workHandlerWithProgress(progressCallback); return(new object()); }, (o, msg, done) => { this.progressHandler(msg, done); }, (o, result) => { this.successHandler(); }, (o, x) => { this.exceptionHandler(x); }); }