コード例 #1
0
        public IScheduledTask ScheduleUpdate(ILifecycleObject @object, Action action, string taskName, ExecutionTargetContext target)
        {
            if ([email protected])
            {
                return(null);
            }

            ScheduledTask task = new ScheduledTask(++taskIds, taskName, this, @object, action, target);

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

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

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

            return(task);
        }
コード例 #2
0
        protected internal virtual void RunTask(IScheduledTask t)
        {
            var task = (ScheduledTask)t;

            if (!task.IsReferenceAlive)
            {
                InternalTasks.Remove(task);
                return;
            }

            if (!t.Owner.IsAlive)
            {
                return;
            }

            if (task.StartTime != null && task.StartTime > DateTime.UtcNow)
            {
                return;
            }

            if (task.EndTime != null && task.EndTime < DateTime.UtcNow)
            {
                task.EndTime = DateTime.UtcNow;
                RemoveTask(task);
                {
                    return;
                }
            }

            if (task.Period != null &&
                task.LastRunTime != null &&
                DateTime.UtcNow - task.LastRunTime < task.Period)
            {
                return;
            }

            try
            {
            }
            catch (Exception ex)
            {
                Container.Resolve <ILogger>().LogError("An exception occured in task: " + task.Name, ex);
                task.EndTime = DateTime.UtcNow;
                RemoveTask(task);
                return;
            }

            if (task.ExecutionTarget == ExecutionTargetContext.NextFrame ||
                task.ExecutionTarget == ExecutionTargetContext.NextPhysicsUpdate ||
                task.ExecutionTarget == ExecutionTargetContext.Async ||
                task.ExecutionTarget == ExecutionTargetContext.NextAsyncFrame ||
                task.ExecutionTarget == ExecutionTargetContext.Sync)
            {
                task.EndTime = DateTime.UtcNow;
                RemoveTask(task);
            }
        }
コード例 #3
0
 protected virtual void RemoveTask(ITask task)
 {
     InternalTasks.Remove(task);
 }
コード例 #4
0
 protected virtual void RemoveTask(IScheduledTask task)
 {
     InternalTasks.Remove((ScheduledTask)task);
 }