private void WaitForTaskToComplete(Task task, RepetitiveTask t) { while (task.State == TaskState.Running) { this.OnWaitingForTaskToCompleteEvent(new TaskEventArgs { Task = t }); Thread.Sleep(500); } }
private void AddTrigger(TaskDefinition definition, RepetitiveTask task) { switch (task.Type) { case RepetitiveTaskType.Daily: { var trigger = (DailyTrigger)definition.Triggers.Add(new DailyTrigger()); trigger.StartBoundary = task.StartAt.HasValue ? task.StartAt.Value : DateTime.Now; } break; case RepetitiveTaskType.Weekly: { var trigger = (WeeklyTrigger)definition.Triggers.Add(new WeeklyTrigger(task.DaysOfWeek)); trigger.StartBoundary = task.StartAt.HasValue ? task.StartAt.Value : DateTime.Now; } break; case RepetitiveTaskType.Monthly: { var trigger = (MonthlyTrigger)definition.Triggers.Add(new MonthlyTrigger(task.DayOfMonth)); trigger.StartBoundary = task.StartAt.HasValue ? task.StartAt.Value : DateTime.Now; } break; case RepetitiveTaskType.Interval: { var trigger = (TimeTrigger)definition.Triggers.Add(new TimeTrigger()); trigger.StartBoundary = task.StartAt.HasValue ? task.StartAt.Value : DateTime.Now; trigger.Repetition.Interval = task.Interval; } break; default: throw new NotSupportedException("The task type is not supported."); } definition.Settings.StopIfGoingOnBatteries = false; definition.Settings.DisallowStartIfOnBatteries = false; }