/// <summary> /// Invokes an arbitrary block of code asynchronously, executing a continuation upon completion or error handler upon failure. /// </summary> /// <remarks> /// The invocation is tied to the lifetime of the specified application component. That is, if the component is stopped, any /// asynchronous invocations pending completion will be discarded. /// </remarks> /// <param name="component"></param> /// <param name="asyncCode"></param> /// <param name="continuationCode"></param> /// <param name="errorHandler"></param> public static void Invoke( IApplicationComponent component, AsyncTask.Action asyncCode, AsyncTask.Action continuationCode, Action <Exception> errorHandler) { var ctm = GetComponentTaskManager(component); ctm.Invoke(asyncCode, continuationCode, errorHandler); }
public void Invoke( AsyncTask.Action asyncCode, AsyncTask.Action successHandler, Action <Exception> errorHandler) { var task = new AsyncTask(); _asyncTasks.Add(task); task.Run(asyncCode, delegate { _asyncTasks.Remove(task); task.Dispose(); successHandler(); }, delegate(Exception e) { _asyncTasks.Remove(task); task.Dispose(); errorHandler(e); }); }