ASP.NET Web APIで特定の時間に毎日実行し、更新ステータス/レコード/電子メール、SMSの生成などの特定のタスクを実行する必要があるいくつかの関数を作成します。WebApiのWindowsタスクスケジューラまたはTaskService関数
iは
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");
}
}
}
コード
でTaskServiceを作成する必要がありますか私は、.batファイルを作成する必要がありますし、タスクスケジューラで新しいタスクを作成します。
私は、スケジュールされたタイマーを持つWindowsサービスを提案します。私はこの実装をいくつかの生産タスクで使用します。 Windowsがフェイルオーバー、通知、ログ、再起動などを処理できるようにし、Visual StudioのC#でWindowsサービスを構築することは、テンプレートを使用することで非常に簡単です。 https://www.codeproject.com/Articles/6507/NET-Scheduled-Timer – Mangist