Home >Backend Development >C++ >How Can I Create and Schedule Tasks in C# WPF Using the Task Scheduler?
This article introduces how to create and schedule the task in the Windows task scheduling program in the C# WPF project.
Use the task scheduling program to host the packaging device
<code class="language-csharp">using System; using Microsoft.Win32.TaskScheduler; class Program { static void Main(string[] args) { 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)); // 打开记事本并显示c:\test.log文件 ts.RootFolder.RegisterTaskDefinition(@"TestTask", td); // 注册任务,名称为"TestTask" ts.RootFolder.DeleteTask("TestTask"); // 删除任务 } } }</code>Other choices
The above is the detailed content of How Can I Create and Schedule Tasks in C# WPF Using the Task Scheduler?. For more information, please follow other related articles on the PHP Chinese website!