Cancellation Scope

Estimated reading: 2 minutes

The Cancellation Scope activity enables you to define a primary task along with a cleanup or recovery action that executes only if the primary task is interrupted before completion. It is useful for managing long-running or interruptible processes where cleanup is required.

Structure

The Cancellation Scope is divided into two sections:

a. Body: Contains the primary workflow main task.
b. Cancellation Handler: Contains cleanup or recovery actions that execute when the Body is cancelled before completion.

Properties

DisplayName: Specifies the name of the activity. This can be customized to improve readability and aid in troubleshooting.

How Cancellation Scope Works

Component Overview Behavior
Body Represents the main execution flow of the workflow, typically including operations such as processing data, opening applications, or waiting for a task to complete. Executes first and, if it completes successfully, the workflow ends normally.
CancellationHandler Defines the cleanup or recovery actions executed when the Body is cancelled. Runs only when the Body is interrupted before completion and performs actions such as closing applications, stopping processes, or handling partially completed work.

Example: Using Cancellation Scope

Steps

1. Add the Cancellation Scope activity to a new workflow.
2. In the Body section, add a Write Line activity and set the message to Process Started, then add a Delay 5s activity, and then add a Write Line activity and set the message to Process Completed.
3. In the Cancellation Handler section, add a Write Line activity and set the message to Process Cancelled.

Result

If the process completes normally, the output will be a sequence where the workflow first prints Process Started and then prints Process Completed.

If the process is cancelled during the delay period, the Cancellation Handler is triggered and the output becomes a sequence where the workflow first prints Process Started and then prints Process Cancelled.

Share this Doc

Cancellation Scope

Or copy link

CONTENTS
Robility Chatbot
Robility Assistant
Online