# Page.CancelBackgroundTask(Integer) Method
> Version: _Available or changed with runtime version 4.0._
Attempt to cancel a page background task.
## Syntax
```al
[Ok := ]  Page.CancelBackgroundTask(TaskId: Integer)
```
## Parameters
Page
Type: page-data-type
An instance of the page-data-type data type.
TaskId
Type: ../integer/integer-data-type
Specifies the ID of the page background task to cancel. The ID is assigned to the task when it is queued by the EnqueueBackgroundTask method.
## Return Value
*[Optional] Ok*
Type: ../boolean/boolean-data-type
true if the page background task was marked for cancellation; otherwise false.
## Example
The following example uses the CancelBackgroundTask method to cancel an existing page background task, based on its task ID.
```al
var​
  WaitTaskId: Integer;​
​
trigger OnAfterGetRecord()​
var​
  TaskParameters: Dictionary of [Text, Text];​
begin​
  if (WaitTaskId > 0) then​
    Currpage.CancelBackgroundTask(WaitTaskId);​
    TaskParameters.Add('Wait', '1000');
    CurrPage.EnqueueBackgroundTask(WaitTaskId, 50100, TaskParameters, 1000, PageBackgroundTaskErrorLevel::Warning);
end;
```
CurrPage is a system-defined variable. See ../../devenv-system-defined-variables.
## Related information
../../devenv-page-background-tasks
page-data-type
../../devenv-system-defined-variables
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

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/page/page-cancelbackgroundtask-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. https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/page/page-cancelbackgroundtask-method/
