Пример #1
0
        public void ChangeDelay(int minutes)
        {
            CheckTask();

            // recreate the trigger
            GetTask.Definition.Triggers.Clear();
            GetTask.Definition.Triggers.Add(GenerateLogonTrigger(minutes));
            GetTask.RegisterChanges();
        }
Пример #2
0
        /// <summary>
        /// checks the task if the execution path is up2date (because the application should be portable)
        /// </summary>
        public void CheckTask()
        {
            if (GetTask.Definition.Actions.Count != 1 || GetTask.Definition.Triggers.Count != 1)
            {
                // no idea what happened - recreate the task
                Logging.WriteLine("Task is no longer valid. Removing the complete task and readding it.");
                TaskService.Instance.RootFolder.DeleteTask(GetTask.Name);
                CreateTask();
            }

            // check action
            ExecAction ea = (ExecAction)GetTask.Definition.Actions.First();

            if (!ea.Path.Equals(Application.ExecutablePath))
            {
                // need to update the current task path
                Logging.WriteLine("Task action path does not match current path - updating action path.");
                ea.Path             = Application.ExecutablePath;
                ea.WorkingDirectory = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
                GetTask.RegisterChanges();
            }
        }