
Asynchronous jobs
What is needed to create a job dispatcher of asynchronous tasks? Not much! Read this article to get an example of a class that runs several tasks asynchronously and stores the result in a table.
Since proof is in the pudding, it's always nice to see how something works and then pull it apart to understand all the various components. This example does not contain much, only a class and a table.
Create a new table
This table should be called TstTable and contain one string field; ResultString and have Created date time activated. Download the tstTable.xml and put it into the model of your choice.
Create a new class
Download the tstRunAsyncClass.xml and put it into the same model as the table. The class contains code that produces 20 tasks that run asynchronously. Each task has a number, given by the order of creation, and will insert a record in the tstTable with the text "Async task #" + the number of the task. Since createdDateTime is activated on the table, we get a timestamp for each task.

After a build and a sync of the project/model it's time to run the class. And as soon as the class 'tstRunAsyncClass' has completed, you can view the data in the table using the SysTableBrowser.
mi=sysclassrunner&cls=tstRunAsyncClass
mi=SysTableBrowser&TableName=tstTable
Since there isn't a custom index set, the data is sorted by the default RecId column, reflecting the order in which it was inserted. As a result, the task numbers are not in any specific order. Running the class multiple times will produce different task orders.
ResultString | createdDateTime | RecId |
---|---|---|
Async task # 3 | 22.10.2024 21:02:17 | 5637144576 |
Async task # 0 | 22.10.2024 21:02:17 | 5637144577 |
Async task # 2 | 22.10.2024 21:02:17 | 5637144578 |
Async task # 7 | 22.10.2024 21:02:17 | 5637144579 |
Async task # 6 | 22.10.2024 21:02:17 | 5637144580 |
Async task # 5 | 22.10.2024 21:02:18 | 5637144581 |
Async task # 4 | 22.10.2024 21:02:18 | 5637144582 |
Async task # 1 | 22.10.2024 21:02:18 | 5637144583 |
Async task # 8 | 22.10.2024 21:02:18 | 5637144584 |
Async task # 9 | 22.10.2024 21:02:18 | 5637144585 |
Async task # 11 | 22.10.2024 21:02:18 | 5637144586 |
Async task # 12 | 22.10.2024 21:02:18 | 5637144587 |
Async task # 13 | 22.10.2024 21:02:18 | 5637144588 |
Async task # 15 | 22.10.2024 21:02:19 | 5637144589 |
Async task # 14 | 22.10.2024 21:02:19 | 5637144590 |
Async task # 10 | 22.10.2024 21:02:19 | 5637144591 |
Async task # 16 | 22.10.2024 21:02:19 | 5637144592 |
Async task # 17 | 22.10.2024 21:02:19 | 5637144593 |
Async task # 18 | 22.10.2024 21:02:19 | 5637144594 |
Async task # 19 | 22.10.2024 21:02:20 | 5637144595 |