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.

Aa446824.wedge(en-us,VS.85).gifTo create an idle trigger for a known task

  1. 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.)
  2. Call ITaskScheduler::Activate to get the ITask interface of the task object. (Note that this example gets the "Test Task" task.)
  3. Call SetIdleWait to set how long the system must remain idle before the trigger will fire. (Note that SetIdleWait is inherited from IScheduledWorkItem.)
  4. Define the TASK_TRIGGER structure and call CreateTrigger to create the idle trigger. (Note that CreateTrigger is inherited from IScheduledWorkItem.)
  5. 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.)
  6. Call ITask::Release to release all resources. (Note that Release is an IUnknown method inherited by ITask.)
For a code example ofSee
Creating an idle trigger for an existing task C/C++ Code Example: Creating an Idle Trigger

 

Related topics

Task Scheduler 1.0 Examples

 

 

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.