當前位置: 首頁>>代碼示例>>C#>>正文


C# TaskScheduler.TaskService類代碼示例

本文整理匯總了C#中Microsoft.Win32.TaskScheduler.TaskService的典型用法代碼示例。如果您正苦於以下問題:C# TaskService類的具體用法?C# TaskService怎麽用?C# TaskService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TaskService類屬於Microsoft.Win32.TaskScheduler命名空間,在下文中一共展示了TaskService類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: StartNew

        private void StartNew(DateTime startTime, string action, string parameters, string taskName)
        {
            using (TaskService ts = new TaskService())
            {
                TaskDefinition td = ts.NewTask();
                td.Principal.RunLevel = TaskRunLevel.Highest;
                td.RegistrationInfo.Description = "instaprinter";

                td.Triggers.Add(new TimeTrigger(startTime));
                td.Actions.Add(new ExecAction(action, parameters));

                // Retrieve the task, change the trigger and re-register it
                Task t = ts.GetTask(taskName);
                if (t != null)
                {
                    td = t.Definition;
                    td.Triggers[0].StartBoundary = startTime;

                    ts.RootFolder.RegisterTaskDefinition(taskName, td);
                }
                else
                {
                    ts.RootFolder.RegisterTaskDefinition(taskName, td);
                }
            }
        }
開發者ID:kobyb1988,項目名稱:PhotoBox,代碼行數:26,代碼來源:SchedulerService.cs

示例2: FindTask

 internal static void FindTask(TaskService ts, System.IO.TextWriter output, params string[] arg)
 {
     try
     {
         Task t = ts.FindTask(arg[0]);
         if (t == null)
             output.WriteLine(string.Format("Task '{0}' not found.", arg[0]));
         else
         {
             output.WriteLine(string.Format("Task '{0}' found. Created on {1:g} and last run on {2:g}.", t.Name, t.Definition.RegistrationInfo.Date, t.LastRunTime));
             if (t.Definition.Triggers.ContainsType(typeof(CustomTrigger)))
             {
                 foreach (var tr in t.Definition.Triggers)
                 {
                     CustomTrigger ct = tr as CustomTrigger;
                     if (ct != null && ct.Properties.Count > 0)
                     {
                         output.WriteLine("Custom Trigger Properties:");
                         int i = 0;
                         foreach (var name in ct.Properties.Names)
                             output.WriteLine("{0}. {1} = {2}", ++i, name, ct.Properties[name]);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         output.WriteLine(ex.ToString());
     }
 }
開發者ID:tablesmit,項目名稱:task-scheduler-managed-wrapper,代碼行數:31,代碼來源:Program.cs

示例3: AddStores2TaskScheduler

 public static void AddStores2TaskScheduler(string strStoresPath, string strActionPath)
 {
     string[] strXMLFiles = Directory.GetFiles(strStoresPath, "*.xml");
     TaskService ts = new TaskService();
     Console.ForegroundColor = ConsoleColor.Cyan;
     Console.WriteLine("");
     Console.WriteLine("Adding stores to the Task Scheduler");
     Console.ForegroundColor = ConsoleColor.Green;
     foreach (string strXMLFile in strXMLFiles)
     {
         string storeName = Path.GetFileName(strXMLFile);
         string taskName = @"BC Store " + storeName;
         Task t = ts.FindTask(taskName);
         if (t == null)
         {
             Console.WriteLine("  + " + storeName);
             DailyTrigger dt = new DailyTrigger();
             dt.StartBoundary = DateTime.Today.Date;
             dt.Repetition.Duration = TimeSpan.FromMinutes(1430);
             dt.Repetition.Interval = TimeSpan.FromMinutes(2);
             ts.AddTask(taskName, dt, new ExecAction(strActionPath, strXMLFile, null));
             Thread.Sleep(500);
         }
     }
     Console.ForegroundColor = ConsoleColor.Cyan;
     Console.WriteLine("All stores added");
     Console.WriteLine("");
     Console.WriteLine("");
     Console.ForegroundColor = ConsoleColor.White;
 }
開發者ID:rogerlio,項目名稱:csharp-proj,代碼行數:30,代碼來源:Utils.cs

示例4: AddTask

        public void AddTask(int min, int hour, bool restart)
        {
            var taskService = new TaskService();

            //Create task definition
            var taskDefinition = taskService.NewTask();
            taskDefinition.RegistrationInfo.Description = min + "@" + hour + "@" + ((restart) ? "r" : "s");
            taskDefinition.Principal.UserId = "SYSTEM";

            var trigger = new DailyTrigger
            {
                StartBoundary = DateTime.Today + TimeSpan.FromHours(hour) + TimeSpan.FromMinutes(min)
            };

            taskDefinition.Triggers.Add(trigger);

            //Create task action
            var fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"Power.exe");

            taskDefinition.Actions.Add(restart
                ? new ExecAction(fileName, "reboot \"This computer is going to reboot.\"")
                : new ExecAction(fileName, "shutdown \"This computer is going to shutdown to save power.\""));

            taskDefinition.Settings.AllowDemandStart = false;
            taskDefinition.Settings.DisallowStartIfOnBatteries = false;
            taskDefinition.Settings.DisallowStartOnRemoteAppSession = false;
            taskDefinition.Settings.StopIfGoingOnBatteries = false;

            taskService.RootFolder.RegisterTaskDefinition(@"FOG\" + taskDefinition.RegistrationInfo.Description,
                taskDefinition);
            taskService.Dispose();
        }
開發者ID:darksidemilk,項目名稱:fog-client,代碼行數:32,代碼來源:WindowsGreen.cs

示例5: IsAutostart

 public static bool IsAutostart()
 {
     using (TaskService ts = new TaskService())
     {
         Microsoft.Win32.TaskScheduler.Task task = ts.GetTask("Touchmote");
         return task != null;
     }
 }
開發者ID:marquinio007,項目名稱:Touchmote,代碼行數:8,代碼來源:Autostart.cs

示例6: DeleteTask

 public void DeleteTask(string name)
 {
     using (TaskService ts = new TaskService())
     {
         if (ts.GetTask(name) != null)
         {
             ts.RootFolder.DeleteTask(name);
         }
     }
 }
開發者ID:adsnaider,項目名稱:Automated-House,代碼行數:10,代碼來源:Usuarios.cs

示例7: modifyTask

 public static void modifyTask(DailyTrigger dt)
 {
     using (TaskService ts = new TaskService())
     {
         Task t = ts.GetTask("taxiService");
        TaskDefinition td = t.Definition;
        td.Triggers.Add(dt);
        ts.RootFolder.RegisterTaskDefinition(@"taxiService", td);
     }
 }
開發者ID:jozreel,項目名稱:Projects,代碼行數:10,代碼來源:task+scheduler.cs

示例8: RunTask

 public static void RunTask()
 {
     using (TaskService ts = new TaskService())
     {
         Task t = ts.GetTask("CudaAdministratorSkipUAC");
         if (t != null)
         {
             t.Run();
         }
     }
 }
開發者ID:perezdev,項目名稱:CUDA-Administrator,代碼行數:11,代碼來源:ScheduleTask.cs

示例9: Install

        public void Install(IEnumerable<RepetitiveTask> tasks)
        {
            tasks = tasks.ToList();

            using (var ts = new TaskService())
            {
                var path = Assembly.GetEntryAssembly().Location;

                foreach (var t in tasks)
                {
                    var definition = ts.NewTask();
                    definition.Settings.Enabled = true;
                    definition.RegistrationInfo.Description = t.Description;

                    AddTrigger(definition, t);

                    definition.Actions.Add(new ExecAction(t.Path ?? path, t.Parameters, Path.GetDirectoryName(path)));

                    ts.RootFolder.RegisterTaskDefinition(
                        t.Name,
                        definition,
                        TaskCreation.CreateOrUpdate,
                        "SYSTEM",
                        null,
                        TaskLogonType.ServiceAccount);

                    OnTaskInstalledEvent(new TaskEventArgs { Task = t });
                }
            }
        }
開發者ID:bitdiff,項目名稱:wintasks,代碼行數:30,代碼來源:TaskHelper.cs

示例10: CreateTask

        public void CreateTask(TaskService service)
        {
            var path = Application.StartupPath;

            try
            {
                var task = service.AddTask("SP_Field_Monitor",
                                           new DailyTrigger() { StartBoundary = DateTime.Parse("10:00:00 AM") },
                                           new ExecAction(path + "\\SPFieldMonitor.exe",
                                                          "-user [email protected] -password \"!thisisatestitisonlyatest!\"",
                                                          path), "SYSTEM");

                var trigger = new DailyTrigger() { StartBoundary = DateTime.Parse("11:00:00 AM") };
                trigger.Repetition.Duration = TimeSpan.FromHours(22);
                trigger.Repetition.Interval = TimeSpan.FromHours(1);

                var checkTask = service.AddTask("SP_Field_Monitor_Check", trigger,
                                           new ExecAction(path + "\\SPFieldMonitor.exe",
                                                          "-user [email protected] -password \"!thisisatestitisonlyatest!\" -check",
                                                          path), "SYSTEM");

                MessageBox.Show(
                    "The daily task has been scheduled.\nIf you move any of the Field Monitor executables, you will need to click this button again to reschedule the task.",
                    "Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            catch (UnauthorizedAccessException)
            {
                MessageBox.Show(
                    "You need administrator privileges to schedule this task. Try running the program as an administrator.",
                    "Insufficient Access Rights", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
開發者ID:jwarnes,項目名稱:backupMon,代碼行數:32,代碼來源:frmMain.cs

示例11: TaskShedulerWrapper_Dev2TaskSettings_PassThrough

 public void TaskShedulerWrapper_Dev2TaskSettings_PassThrough()
 {
     var service = new TaskService();
     var task =service.NewTask();
     var settings = new Dev2TaskSettings(task.Settings);
     settings.AllowDemandStart = true;
     settings.DeleteExpiredTaskAfter = new TimeSpan(2);
     settings.AllowHardTerminate = true;
     settings.DisallowStartOnRemoteAppSession = true;
     settings.Enabled = false;
     settings.ExecutionTimeLimit = new TimeSpan(3);
     settings.Hidden = true;
     settings.MultipleInstances = TaskInstancesPolicy.IgnoreNew;
     settings.Priority = ProcessPriorityClass.High;
     settings.RestartCount = 3;
     settings.StartWhenAvailable = false;
     settings.WakeToRun = true;
     var native = task.Settings;
     Assert.AreEqual(settings.AllowDemandStart,native.AllowDemandStart);
     Assert.AreEqual(settings.AllowHardTerminate,native.AllowHardTerminate);
     Assert.AreEqual(settings.DeleteExpiredTaskAfter,native.DeleteExpiredTaskAfter);
     Assert.AreEqual(settings.DisallowStartOnRemoteAppSession,native.DisallowStartIfOnBatteries);
     Assert.AreEqual(settings.Enabled,settings.Enabled);
     Assert.AreEqual(settings.ExecutionTimeLimit,native.ExecutionTimeLimit);
     Assert.AreEqual(settings.ExecutionTimeLimit,native.ExecutionTimeLimit);
     Assert.AreEqual(settings.Hidden,native.Hidden);
     Assert.AreEqual(settings.MultipleInstances,native.MultipleInstances);
     Assert.AreEqual(settings.RestartCount,native.RestartCount);
     Assert.AreEqual(settings.Priority,native.Priority);
     Assert.AreEqual(settings.RestartInterval,native.RestartInterval);
     Assert.AreEqual(settings.StartWhenAvailable,native.StartWhenAvailable);
     Assert.AreEqual(settings.WakeToRun,native.WakeToRun);
 }
開發者ID:Robin--,項目名稱:Warewolf,代碼行數:33,代碼來源:Dev2TaskSettingsTest.cs

示例12: CreateOrActivate

		public bool CreateOrActivate(String TaskName, String FullExecuteableFileName, TimeSpan RetryIntervall)
			{
			//if (!IsAdministrator())
			//	return false;
			using (TaskService taskService = new TaskService())
				{
				Task task = taskService.FindTask(TaskName);
				if (task == null)
					{
					TaskDefinition taskDefinition = CreateTask(taskService, TaskName, RetryIntervall);
					taskDefinition.Actions.Add(new ExecAction(FullExecuteableFileName));
					
					taskDefinition.RegistrationInfo.Description = $"WPMedia created Task for " +
									$"{Path.GetFileNameWithoutExtension(FullExecuteableFileName)}";
					taskDefinition.Settings.MultipleInstances = TaskInstancesPolicy.IgnoreNew;
					taskDefinition.Settings.AllowDemandStart = true;
					taskDefinition.Settings.AllowHardTerminate = false;
					taskDefinition.Settings.DisallowStartIfOnBatteries = false;
					taskDefinition.RegistrationInfo.Author = "WPMediaAutoRegistration";
					if (taskDefinition.Validate())
						task = taskService.RootFolder.RegisterTaskDefinition(TaskName, taskDefinition);
					else
						throw new Exception($"{TaskName} Scheduling for {FullExecuteableFileName} failed");
					}
				task.Enabled = true;
				}
			return true;
			}
開發者ID:heinzsack,項目名稱:DEV,代碼行數:28,代碼來源:TaskSchedulingFunctions.cs

示例13: clearSchedules

 public void clearSchedules()
 {
     string strTaskID = "";
     try
     {
         // Get the service on the local machine
         TaskService ts = new TaskService();
         // Delete Schedules
         DataTable dt = this.GetSchedules(1);
         foreach (DataRow dr in dt.Rows)
         {
             strTaskID = dr["TaskID"].ToString();
             if (ts.FindTask(strTaskID, true) != null)
             {
                 // Remove the task we just created
                 ts.RootFolder.DeleteTask(strTaskID);
             }
             // Delete schedules follow taskid
             this.DeleleSchedules(strTaskID);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
開發者ID:colobaena,項目名稱:prediction-tool,代碼行數:26,代碼來源:clsOddBO.cs

示例14: RemoveTask

 public void RemoveTask(int min, int hour, bool restart)
 {
     var taskService = new TaskService();
     var task = min + "@" + hour + "@" + ((restart) ? "r" : "s");
     taskService.RootFolder.DeleteTask(@"FOG\" + task);
     taskService.Dispose();
 }
開發者ID:darksidemilk,項目名稱:fog-client,代碼行數:7,代碼來源:WindowsGreen.cs

示例15: StartupTaskExists

 public static bool StartupTaskExists()
 {
     using (TaskService _taskService = new TaskService())
     {
         return _taskService.FindTask(_taskName) != null;
     }
 }
開發者ID:CSpellmanKrieg,項目名稱:SidebarDiagnostics,代碼行數:7,代碼來源:Helpers.cs


注:本文中的Microsoft.Win32.TaskScheduler.TaskService類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。