当前位置: 首页>>代码示例>>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;未经允许,请勿转载。