Search code examples
c#scheduled-taskswindows-task-scheduler

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

  • 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();