protected void ScheduleImports() { lock (_syncObj) { ITaskScheduler scheduler = ServiceRegistration.Get <ITaskScheduler>(); ISettingsManager settingsManager = ServiceRegistration.Get <ISettingsManager>(); _importerTaskId = _settings.Settings.ImporterScheduleId; // Allow removal of existing import tasks if (!_settings.Settings.EnableAutoRefresh) { if (_importerTaskId != Guid.Empty) { scheduler.RemoveTask(_importerTaskId); _importerTaskId = _settings.Settings.ImporterScheduleId = Guid.Empty; _ignoreChange = true; // Do not react on next setting's change message! settingsManager.Save(_settings.Settings); } return; } Schedule schedule = new Schedule { Hour = (int)_settings.Settings.ImporterStartTime, Minute = (int)((_settings.Settings.ImporterStartTime - (int)_settings.Settings.ImporterStartTime) * 60), Day = -1, Type = ScheduleType.TimeBased }; Task importTask = new Task("ImporterWorker", schedule, Occurrence.Repeat, DateTime.MaxValue, true, true); if (_importerTaskId == Guid.Empty) { _importerTaskId = scheduler.AddTask(importTask); _settings.Settings.ImporterScheduleId = _importerTaskId; _ignoreChange = true; // Do not react on next setting's change message! settingsManager.Save(_settings.Settings); } else { scheduler.UpdateTask(_importerTaskId, importTask); } } }