private static void ExecuteTryUpdateScheduledTask(string v1TaskName, SchedulerManager sm) { try { sm.DeleteTask(v1TaskName); if (!sm.TaskIsSet()) sm.InstallTask(); else sm.CheckConsistency(); } catch (Exception ex) { MessageBox.Show($"There was an error: [{ex.Message}]", Branding.MessageBoxHeader); }; }
static public void ProcessSingleTask() { if (HasDeleteTaskOption) { SchedulerManager sm = new SchedulerManager(); if (sm.TaskIsSet()) { var result = App.CommandLineOptions.AskDeleteTask ? MessageBox.Show($"You have a scheduled task to check for updates of {Branding.TargetProduct}.{Environment.NewLine + Environment.NewLine}Do you want to remove this scheduled task?", Branding.MessageBoxHeader, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) : MessageBoxResult.Yes; if (result == MessageBoxResult.Yes) { sm.DeleteTask(); if (!App.CommandLineOptions.SilentlyDeleteTask) { MessageBox.Show("Scheduled task has been removed successfully", Branding.MessageBoxHeader, MessageBoxButton.OK, MessageBoxImage.Information); } } } } if (HasSetTaskOption) { SchedulerManager sm = new SchedulerManager(); // re-create the task without asking if (App.CommandLineOptions.ForceSetTask) { sm.ForceReInstallTask(); } // ask if task is present and not-consistent, otherwise create it silently if (App.CommandLineOptions.SetTaskAskIfNonConsistent) { if (sm.TaskIsSet()) { sm.CheckConsistency(); } else { sm.ForceReInstallTask(); } } } }