Пример #1
0
        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);
        }
Пример #2
0
 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();
     }
 }
Пример #3
0
        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());
            }
        }
Пример #4
0
 public static void BackgroundAction(Action backgroundAction, Action callback, EndMode endMode, TaskImplMode taskMode)
 {
     BackgroundAction(null, backgroundAction, default(Action), callback, endMode, taskMode);
 }
Пример #5
0
 public static void BackgroundAction(Action backgroundAction, EndMode endMode, TaskImplMode taskMode)
 {
     BackgroundAction(backgroundAction, default(Action), endMode, taskMode);
 }
Пример #6
0
        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);
            }
        }
Пример #7
0
 public static void BackgroundAction(Action backgroundAction, Action callback, EndMode endMode, TaskImplMode taskMode)
 {
     BackgroundAction(null, backgroundAction, default(Action), callback, endMode, taskMode);
 }
Пример #8
0
 public static void BackgroundAction(Action backgroundAction, EndMode endMode, TaskImplMode taskMode)
 {
     BackgroundAction(backgroundAction, default(Action), endMode, taskMode);
 }