Event Handlers
Event handlers are used to overcome issues with interruptive and blocking activities.
Blocking activities contain a job that has to wait until a certain activity is executed. When using blocking activities, all events have to be handled in the order the process was designed. However, it is not possible to design a process without knowing when a message is received. A shopping cart is a good example of a process where adding and removing items is done in a random order by the shopper.
Event handlers allow asynchronous event processing. They are always attached to a scope and execute parallel to the main business logic of the process, so they are associated with an operation that is a part of the process.
Each event handler is associated with one process and has access to that process. An event handler can be executed multiple times during the process execution and it is executed in parallel with the other tasks within the scope or process. The tasks within a scope or process can be terminated, prior to executing the tasks within the event handler, using the Cancel Scope Execution option.
Consider the Mortgage Service Provider process shown in the following figure. The Mortgage service contains three operations - SubmitMortgageApp, SubmitFinDoc, and CancelMortgageApp. The CancelMortgageApp operation is defined in the event handler container. Both the CancelMortgageApp and SubmitFinDoc operations have a correlation key obtained from the response to the SubmitMortgageApp operation. After submitting an application, if the consumer invokes the CancelMortgageApp operation with the correlation key before submitting the documents, the event handler containing the implementation for the CancelMortgageApp operation is executed in parallel to the main process. The engine does not wait for the SubmitFinDoc activity to be executed.