Running asynchronous patterns
When you have complex calculations that need to start from a UI trigger (like AL code that needs to update statistical values on a page) and these calculations require time to complete, to avoid blocking the UI thread, it’s often recommended to offload the task execution to a background session.
To execute a task in the background, you can use the following:
StartSession
: Permits you to execute a new session in parallel. The new session will run in the background and can perform read and write transactions.Task Scheduler
: Used in code to execute tasks in the background. These tasks are queued up and survive between server restarts (the process will be retried when the server is up again).Page Background Task
: Permits you to execute read-only tasks in a background session that can be started from a main UI thread. Details about how to use them were explained in Chapter 5, Writing Code for Extensibility.