Reputation: 2629
I have some code I want to run every 30 minutes. In the windows task scheduler -> Create Task -> Action -> new - there is a place to insert it a script/program. My question what kind of project I need to create to add there my program, and what kind of file I need to add - dll?
What I wish to run every 30 minutes is a 30~ lines of code that get something from then net, process it and insert it to a db.
Thanks.
Upvotes: 1
Views: 6629
Reputation: 175
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");
}
}
}
Upvotes: 4
Reputation: 887195
Task Scheduler runs ordinary EXEs.
You don't need to do anything special.
Upvotes: 5