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); }
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); } }
protected virtual void RemoveTask(ITask task) { InternalTasks.Remove(task); }
protected virtual void RemoveTask(IScheduledTask task) { InternalTasks.Remove((ScheduledTask)task); }