我有一些我想每 30 分钟运行一次的代码。在 Windows 任务计划程序 -> 创建任务 -> 操作 -> 新建 - 有一个地方可以插入脚本/程序。我的问题是我需要创建什么样的项目来添加我的程序,以及我需要添加什么样的文件 - dll?
我希望每 30 分钟运行一次 30~ 行代码,从网络中获取一些东西,处理它并将其插入到数据库中。
谢谢。
我有一些我想每 30 分钟运行一次的代码。在 Windows 任务计划程序 -> 创建任务 -> 操作 -> 新建 - 有一个地方可以插入脚本/程序。我的问题是我需要创建什么样的项目来添加我的程序,以及我需要添加什么样的文件 - dll?
我希望每 30 分钟运行一次 30~ 行代码,从网络中获取一些东西,处理它并将其插入到数据库中。
谢谢。
任务计划程序运行普通的 EXE。
你不需要做任何特别的事情。
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");
}
}
}