Example #1
0
 /// <inheritdoc />
 public ThreadSafeTask(int taskId, string name, ITaskScheduler scheduler, ILifecycleObject owner, Action action, ExecutionTargetContext executionTargetContext)
 {
     TaskId          = taskId;
     Name            = name;
     Scheduler       = scheduler;
     Owner           = owner;
     Action          = action;
     ExecutionTarget = executionTargetContext;
 }
Example #2
0
 internal ScheduledTask(int taskId, string taskName, ITaskScheduler scheduler, ILifecycleObject owner, Action action,
                        ExecutionTargetContext executionTarget)
 {
     Name            = taskName;
     ownerRef        = new Core.Util.WeakReference <ILifecycleObject>(owner);
     Action          = action;
     ExecutionTarget = executionTarget;
     Scheduler       = scheduler;
     TaskId          = taskId;
 }
Example #3
0
 internal SimpleTask(int taskId, string taskName, ITaskScheduler scheduler, ILifecycleObject owner, Action action,
                     ExecutionTargetContext executionTarget)
 {
     Name            = taskName;
     Owner           = owner;
     Action          = action;
     ExecutionTarget = executionTarget;
     Scheduler       = scheduler;
     TaskId          = taskId;
 }
Example #4
0
        internal SimpleTask(ITaskScheduler scheduler, ILifecycleObject owner, Action action,
                            ExecutionTargetContext executionTarget)
        {
            Owner           = owner;
            Action          = action;
            ExecutionTarget = executionTarget;
            Scheduler       = scheduler;

            TaskId = ++taskIds;
        }
 public UnityTask(int taskId, string name, UnityTaskScheduler scheduler,
                  object owner, Action action,
                  ExecutionTargetContext executionTargetContext)
 {
     TaskId          = taskId;
     Name            = name;
     Scheduler       = scheduler;
     Owner           = owner;
     Action          = action;
     ExecutionTarget = executionTargetContext;
 }
Example #6
0
        /// <inheritdoc />
        public ITask ScheduleAt(ILifecycleObject @object, Action action, string taskName, DateTime date, bool runAsync = false)
        {
            ThreadSafeTask         task;
            ExecutionTargetContext context = runAsync ? ExecutionTargetContext.Async : ExecutionTargetContext.NextFrame;

            lock (taskIdLock)
            {
                task = new ThreadSafeTask(taskId++, taskName, this, @object, action, context, TimeSpan.Zero, date, null);
            }

            lock (lockObj)
            {
                tasks.Add(task);
            }

            return(task);
        }
Example #7
0
        /// <inheritdoc />
        public ITask SchedulePeriodically(ILifecycleObject @object, Action action, string taskName, TimeSpan period, TimeSpan?delay = null, bool runAsync = false)
        {
            ThreadSafeTask         task;
            ExecutionTargetContext context = runAsync ? ExecutionTargetContext.Async : ExecutionTargetContext.NextFrame;
            DateTime startTime             = DateTime.UtcNow;

            if (delay != null)
            {
                startTime = startTime.Add(delay.Value);
            }

            lock (taskIdLock)
            {
                task = new ThreadSafeTask(taskId++, taskName, this, @object, action, context, period, startTime, null);
            }

            lock (lockObj)
            {
                tasks.Add(task);
            }

            return(task);
        }
        public virtual ITask ScheduleUpdate(object @object, Action action, string taskName, ExecutionTargetContext target)
        {
            UnityTask task = new UnityTask(++m_NextTaskId, taskName, this, @object, action, target);

            TriggerEvent(task, (sender, @event) =>
            {
                if (target != ExecutionTargetContext.Sync)
                {
                    return;
                }

                if (@event != null && ((ICancellableEvent)@event).IsCancelled)
                {
                    return;
                }

                action();
                m_Tasks.Remove(task);
            });

            return(task);
        }
Example #9
0
        public ITask ScheduleUpdate(ILifecycleObject @object, Action action, string taskName, ExecutionTargetContext target)
        {
            SimpleTask task = new SimpleTask(++taskIds, taskName, this, @object, action, target);

            TriggerEvent(task, (sender, @event) =>
            {
                if (target != ExecutionTargetContext.Sync && @object.IsAlive)
                {
                    return;
                }

                if (@event != null && ((ICancellableEvent)@event).IsCancelled)
                {
                    return;
                }

                action();
                InternalTasks.Remove(task);
            });

            return(task);
        }
Example #10
0
 /// <inheritdoc />
 public ThreadSafeTask(int taskId, string name, ITaskScheduler scheduler, ILifecycleObject owner, Action action, ExecutionTargetContext executionTargetContext, TimeSpan?period, DateTime?startTime, DateTime?endTime) : this(taskId, name, scheduler, owner, action, executionTargetContext)
 {
     Period    = period;
     StartTime = startTime;
     EndTime   = endTime;
 }
Example #11
0
 /// <inheritdoc cref="ITaskScheduler.ScheduleUpdate"/>
 public static IScheduledTask ScheduleTaskUpdate(this ITaskScheduler taskScheduler, ILifecycleObject @owner,
                                                 AsyncAction action, string taskName, ExecutionTargetContext frame)
 {
     return(taskScheduler.ScheduleUpdate(@owner, action().GetAwaiter().GetResult, taskName, frame));
 }
Example #12
0
        /// <inheritdoc />
        public ITask ScheduleUpdate(ILifecycleObject @object, Action action, string taskName, ExecutionTargetContext target)
        {
            ThreadSafeTask task;

            lock (taskIdLock)
            {
                task = new ThreadSafeTask(taskId++, taskName, this, @object, action, target);
            }

            lock (lockObj)
            {
                tasks.Add(task);
            }

            return(task);
        }
Example #13
0
 /// <inheritdoc cref="ITaskScheduler.ScheduleUpdate"/>
 public static IScheduledTask ScheduleTaskUpdate(this ITaskScheduler taskScheduler, ILifecycleObject @owner,
                                                 AsyncAction action, string taskName, ExecutionTargetContext frame)
 {
     return(taskScheduler.ScheduleUpdate(@owner, () => AsyncHelper.RunSync(() => action()), taskName, frame));
 }