반응형
예약 된 작업 만들기
C # WPF 프로젝트를 진행 중입니다. 사용자가 예약 된 작업을 만들어 Windows 작업 스케줄러에 추가 할 수 있도록해야합니다.
인터넷을 검색 할 때 많이 찾지 못해 어떻게 해야하는지, 지시문과 참조를 사용하는 방법은 무엇입니까?
작업 스케줄러 관리 래퍼를 사용할 수 있습니다 .
using System;
using Microsoft.Win32.TaskScheduler;
class Program
{
static void Main(string[] args)
{
// Get the service on the local machine
using (TaskService ts = new TaskService())
{
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";
// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(@"Test", td);
// Remove the task we just created
ts.RootFolder.DeleteTask("Test");
}
}
}
또는 네이티브 API 를 사용 하거나 Quartz.NET을 사용할 수 있습니다 . 자세한 내용은 이것을 참조 하십시오.
이것은 나를 위해 작동합니다 https://www.nuget.org/packages/ASquare.WindowsTaskScheduler/
Fluent API를 훌륭하게 디자인했습니다.
//This will create Daily trigger to run every 10 minutes for a duration of 18 hours
SchedulerResponse response = WindowTaskScheduler
.Configure()
.CreateTask("TaskName", "C:\\Test.bat")
.RunDaily()
.RunEveryXMinutes(10)
.RunDurationFor(new TimeSpan(18, 0, 0))
.SetStartDate(new DateTime(2015, 8, 8))
.SetStartTime(new TimeSpan(8, 0, 0))
.Execute();
참고 URL : https://stackoverflow.com/questions/7394806/creating-scheduled-tasks
반응형
'development' 카테고리의 다른 글
iterator-> second는 무엇을 의미합니까? (0) | 2020.06.19 |
---|---|
많은 C ++ 표준 라이브러리 코드에서 불평등이 (! (a == b))로 테스트되는 이유는 무엇입니까? (0) | 2020.06.19 |
리눅스에서 디스크 활동을 표시하는 htop-like 도구 (0) | 2020.06.19 |
C #에서 Char.IsDigit ()와 Char.IsNumber ()의 차이점 (0) | 2020.06.19 |
Go에서 구조체의 스택과 힙 할당 및 가비지 수집과의 관계 (0) | 2020.06.19 |