Creating an Idle Trigger Example
To create an idle trigger, you must specify an idle trigger when you create the trigger, and you must set the idle time for the task. For information about idle conditions, see Task Idle Conditions.
After creating the idle trigger, call IPersistFile::Save to save the new trigger to disk.
The following procedure describes how to create an idle trigger for a known task.
To create an idle trigger for a known task
- Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (This example assumes that the Task Scheduler service is running.)
- Call ITaskScheduler::Activate to get the ITask interface of the task object. (Note that this example gets the "Test Task" task.)
- Call SetIdleWait to set how long the system must remain idle before the trigger will fire. (Note that SetIdleWait is inherited from IScheduledWorkItem.)
- Define the TASK_TRIGGER structure and call CreateTrigger to create the idle trigger. (Note that CreateTrigger is inherited from IScheduledWorkItem.)
- Save the task with the new idle trigger to disk using IPersistFile::Save. (The IPersistFile interface is a standard COM interface supported by the ITask interface.)
- Call ITask::Release to release all resources. (Note that Release is an IUnknown method inherited by ITask.)
|For a code example of||See|
|Creating an idle trigger for an existing task||C/C++ Code Example: Creating an Idle Trigger|