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
- 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 ITask::GetStatus to find out if the task is running. (Note that GetStatus is an IScheduledWorkItem method inherited by ITask.)
- 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|
Build date: 11/16/2013