public static void BackgroundAction(object target, Action backgroundAction, Action befoe, Action callback, EndMode endMode, TaskImplMode taskMode) { var context = new BackgroundActionContext(endMode, () => { backgroundAction(); return null; }); var container = target == null ? backgroundAction.Target.As<IExtendedPresenter>() : target.As<IExtendedPresenter>(); var task = container.GetMetadata<IBackgroundThreadTask>(); if (task == null) { task = TaskImplFactory.CreateTask(taskMode); if (taskMode != TaskImplMode.UIThread) { container.WasShutdown += (s, e) => task.Dispose(); container.AddMetadata(task); } } //Before if (!befoe.IsNull()) befoe(); //Action task.Enqueue(context); //After if (!callback.IsNull()) Application.Current.Dispatcher.BeginInvoke(callback, DispatcherPriority.ContextIdle); }
public static IBackgroundThreadTask CreateTask(TaskImplMode mode) { switch (mode) { case TaskImplMode.UIThread: return new UIThreadTask(); case TaskImplMode.ThreadPool: return new ThreadPoolTask(ServiceLocator.Current.GetInstance<IThreadPool>()); case TaskImplMode.BackgroundThread: return new BackgroundThreadTask(); case TaskImplMode.BackgroundWorker: return new BackgroundWorkerTask(); default: return new UIThreadTask(); } }
public static IBackgroundThreadTask CreateTask(TaskImplMode mode) { switch (mode) { case TaskImplMode.UIThread: return(new UIThreadTask()); case TaskImplMode.ThreadPool: return(new ThreadPoolTask(ServiceLocator.Current.GetInstance <IThreadPool>())); case TaskImplMode.BackgroundThread: return(new BackgroundThreadTask()); case TaskImplMode.BackgroundWorker: return(new BackgroundWorkerTask()); default: return(new UIThreadTask()); } }
public static void BackgroundAction(Action backgroundAction, Action callback, EndMode endMode, TaskImplMode taskMode) { BackgroundAction(null, backgroundAction, default(Action), callback, endMode, taskMode); }
public static void BackgroundAction(Action backgroundAction, EndMode endMode, TaskImplMode taskMode) { BackgroundAction(backgroundAction, default(Action), endMode, taskMode); }
public static void BackgroundAction(object target, Action backgroundAction, Action befoe, Action callback, EndMode endMode, TaskImplMode taskMode) { var context = new BackgroundActionContext(endMode, () => { backgroundAction(); return(null); }); var container = target == null?backgroundAction.Target.As <IExtendedPresenter>() : target.As <IExtendedPresenter>(); var task = container.GetMetadata <IBackgroundThreadTask>(); if (task == null) { task = TaskImplFactory.CreateTask(taskMode); if (taskMode != TaskImplMode.UIThread) { container.WasShutdown += (s, e) => task.Dispose(); container.AddMetadata(task); } } //Before if (!befoe.IsNull()) { befoe(); } //Action task.Enqueue(context); //After if (!callback.IsNull()) { Application.Current.Dispatcher.BeginInvoke(callback, DispatcherPriority.ContextIdle); } }