Use the task plan program to host the packaging device to create a regular task in C# WPF
In your C# WPF project, you can use the task plan program to host the packaging to create and add timing tasks. The following is the implementation method:
instructions and references:
Code example:
<code class="language-csharp">using System; using Microsoft.Win32.TaskScheduler;</code>
Other choices:
You can also use the native API to create timing tasks. In addition, Quartz.net is another population that schedules operations in the .NET application.<code class="language-csharp">public static void CreateScheduledTask() { // 获取本地计算机上的服务 using (TaskService ts = new TaskService()) { // 创建新的任务定义并赋值属性 TaskDefinition td = ts.NewTask(); td.RegistrationInfo.Description = "执行特定操作"; // 创建一个触发器,该触发器将在每两天执行一次任务 td.Triggers.Add(new DailyTrigger { DaysInterval = 2 }); // 创建一个操作,该操作将在触发器触发时启动记事本 td.Actions.Add(new ExecAction("notepad.exe", "c:\test.log", null)); // 在根文件夹中注册任务 ts.RootFolder.RegisterTaskDefinition(@"TestTask", td); // 删除刚刚创建的任务 ts.RootFolder.DeleteTask("TestTask"); } }</code>
The above is the detailed content of How to Create Scheduled Tasks in C# WPF using Task Scheduler Managed Wrapper?. For more information, please follow other related articles on the PHP Chinese website!