This project has moved. For the latest updates, please go here.

How to setup one-time trigger

Jul 14, 2009 at 8:52 PM


I would like to setup one-time trigger. Could you show me a sample code please?



Jul 17, 2009 at 4:31 AM
using (TaskService ts = new TaskService())
	TaskDefinition td = ts.NewTask();
	td.RegistrationInfo.Description = "Does something";
	td.Principal.LogonType = TaskLogonType.InteractiveToken;

	// Create a trigger that will fire the task at a specific date and time
	td.Triggers.Add(new TimeTrigger {  StartBoundary = new DateTime(2009, 7, 20, 7, 0, 0) });

	// 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("MyTask", td);