Terminating a Task Example

You can terminate a task while it is running by calling IScheduledWorkItem::Terminate.

The following procedure describes how to terminate a task if it is running.

To terminate a task if it is running

  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 ITask::GetStatus to find out if the task is running. (Note that GetStatus is an IScheduledWorkItem method inherited by ITask.)
  4. Check the status of the task and then call ITask::Terminate if the task is running. (Note that Terminate is an IScheduledWorkItem method inherited by ITask.)
For a code example of See
Verifying the status of a known task C/C++ Code Example: Terminating a Task

 

Task Scheduler 1.0 Examples