{"title":"TaskScheduler.CancelTask(Guid) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/taskscheduler/taskscheduler-canceltask-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/taskscheduler/taskscheduler-canceltask-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/taskscheduler/taskscheduler-canceltask-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Cancels and deletes a scheduled task that runs a specific codeunit.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"TaskScheduler.CancelTask(Guid) Method","slug":"taskschedulercanceltaskguid-method","at":0,"chars":1481},{"level":2,"title":"Syntax","slug":"syntax","at":168,"chars":67},{"level":2,"title":"Parameters","slug":"parameters","at":235,"chars":176},{"level":2,"title":"Return Value","slug":"return-value","at":411,"chars":67},{"level":2,"title":"Remarks","slug":"remarks","at":478,"chars":581},{"level":2,"title":"Example","slug":"example","at":1059,"chars":227},{"level":2,"title":"Related information","slug":"related-information","at":1286,"chars":195}],"text":"# TaskScheduler.CancelTask(Guid) Method\n> Version: _Available or changed with runtime version 1.0._\nCancels and deletes a scheduled task that runs a specific codeunit.\n## Syntax\n```al\n[Ok := ]  TaskScheduler.CancelTask(Task: Guid)\n```\n## Parameters\nTask\nType: ../guid/guid-data-type\nSpecifies the unique identifier of the task. The unique identifier is returned by the CreateTask method when creating the task.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\n## Remarks\nScheduled tasks are shown in the Scheduled Tasks page in the client. The TaskScheduler.CancelTask method removes the task entry from the page (the implementation is different for the on-premises version compared to the online version of Business Central).\nThe TaskScheduler.CancelTask method can only cancel pending tasks.\nIf no task exists with the provided task GUID provided to TaskScheduler.CancelTask, then the method returns false (no runtime error occurs).\nFor more information about the task scheduler, see Using the Task Scheduler<../../devenv-task-scheduler>.\n## Example\nThis example shows how to use TaskScheduler.CancelTask to force canceling a task.\n```al\nprocedure CancelTasks(ScheduledTaskId: Guid)\nbegin\n    TaskScheduler.CancelTask(ScheduledTaskId); // Force cancel task\nend;\n```\n## Related information\ntaskscheduler-data-type\nUsing the Task Scheduler<../../devenv-task-scheduler>\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}