Export (0) Print
Expand All

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.

Aa383621.wedge(en-us,VS.85).gifTo 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 ofSee
Verifying the status of a known task C/C++ Code Example: Terminating a Task

 

Related topics

Task Scheduler 1.0 Examples

 

 

Community Additions

ADD
Show:
© 2014 Microsoft