'Use C# Task Scheduler library to End Task
I'm currently using this library for the windows task scheduler https://github.com/dahall/TaskScheduler
What I want is to end the running task. In my research, I found that I can able to disable the task by this code snippet task.Definition.Settings.Enabled = false
. But I did not find any way to end the running task. Can anyone help me with this?
Solution 1:[1]
task.Enabled = false
will disable the single task immediately. task.Definition.Settings.Enabled = false
is used to disable a task before registration.
To terminate a running task, use:
if (task.IsActive && task.State == TaskState.Running) task.Stop();
Solution 2:[2]
Have you tried:
task.Stop();
https://dahall.github.io/TaskScheduler/html/M_Microsoft_Win32_TaskScheduler_Task_Stop.htm
You can retrieve all tasks using:
new TaskService().AllTasks
Solution 3:[3]
I think, what you are looking is Task.Stop()
and RunningTask.Stop()
(inherited from Task
class) methods. Obviously, they stops the registered task immediately. As described in source code:
System account users can stop a task, users with Administrator group privileges can stop a task, and if a user has rights to execute and read a task, then the user can stop the task. A user can stop the task instances that are running under the same credentials as the user account. In all other cases, the user is denied access to stop the task.
Is that what you looking for?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Achyut |
Solution 2 | Noman_1 |
Solution 3 | Tropin Alexey |