private void FireEvent(ControllerActionComplete handler, ControllerActionEventArgs e) { if (handler != null) handler(this, e); }
void ScheduleAction(Action<Object> action, Object param, ControllerActionComplete handler) { Interlocked.Increment(ref taskCount); BindHandler(Task.Factory.StartNew(action, param, cancelFactory.Token), handler); }
void BindHandler(Task task, ControllerActionComplete handler) { if (handler != null) { task.ContinueWith(taskresult => { Interlocked.Decrement(ref taskCount); handler(this, BuildEventArgs()); }, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, scheduler); task.ContinueWith(taskresult => { Interlocked.Decrement(ref taskCount); handler(this, BuildEventArgs(taskresult.Exception)); }, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, scheduler); task.ContinueWith(taskresult => { Interlocked.Decrement(ref taskCount); Console.WriteLine("Controller was cancelled"); // no postback }, CancellationToken.None, TaskContinuationOptions.OnlyOnCanceled, scheduler); } }