Threading and Asynchronous Execution

The tasks developed for the Scheduler system may have need for the use of concurrent and asynchronous programming constructs that, while supported, should be used with caution
and developed in line with best practices to avoid the potential to cause a serious malfunction of the system. Some of these scanarios are defined in this section.

Triggers

When developing a trigger, it is imperative that any threads spawned as part of the custom implementation not allow exceptions that occur within those threads to propagate outside
the thread entry point. Custom trigger classes are executed in the coordinator process and any unhandled exceptions outside of the main execution thread can cause the coordinator process
to be shutdown, which would stop all tasks from being executed and would render the administration website inaccessible. Take the following trigger example:

In the above example, the ProcessComplexCalculations method will inevitably encounter a division by zero exception, which will bubble out of the thread and crash
the process containing the coordinator. In these situations, it is important to handle all exceptions in the thread scope. The example below demonstrates one way to address this:

Tasks and EventListeners

TaskBase and EventListener implementations follow the same pattern as the Trigger implementation in the above example, the difference being
that each task instance is run as its own process so any uncaught thread exceptions will crash the task process but will have no negative impact on the Coordinator or Agent
processes. It is still important to follow the above suggestions to avoid unexpected failures in critical business logic.