Search

Search:

Namespace:

Search Result
.

OnActivityExecutionContextUnload is called before an activity is saved to the database. This means that if the workflow is unloading then this method will be called … additionally if a context is being saved for future compensation then this method will be called on all contained activities. Note that PersistOnClose does not cause OnActivityExecutionContextUnload to be called for the workflow as a whole because the workflow object is not being jettisoned from memory.

.

Dispose is called when we are done with the .NET object representing the activity. So, in the workflow unload case, we will call OnActivityExecutionContextUnload immediately followed by Dispose. In the case of PersistOnClose we will NOT call Dispose on any activities. Only when the activity is being removed from memory will Dispose be called.

.

To ensure consistency between the WorkflowInstance and the database being updated the TransactionScopeActivity is adorned with the PersistOnCloseAttribute. When the TransactionScopeActivity is used the WorkflowRuntime must be configured with a WorkflowPersistenceService. This could be the build in SqlWorkflowPersistenceService or another custom WorkflowPersistenceService.

.
  • After the execution of an Activity adorned with the PersistOnCloseAttribute.
.

If you are developing your own WorkflowActivities make sure you take a good look at the PersistOnClose attribute! If your activity does any work like changing a database its more than likely that you don’t want to have the action executed twice. If the WorkflowRuntime is stopped after your activity has completed without this attribute and is restarted later it will be restarted at the last persisted point, which is before your activity. The result being that your activity is executed again, not quite what you had in mind . The PersistOnClose attribute makes sure that the workflow state is persisted as soon as the activity has completed resulting in a consistent state even after a restart.

.

Of course the PersistOnClose attribute has a drawback and that is that the workflow runtime requires a Workflow persistence service, something you don’t always want. In that case a WorkBatch might be your friend. With a WorkBatch the actual work is postponed until the workflow reached a PersistencePoint. And the end of the workflow is always a PersistencePoint

.

To ensure consistency between the WorkflowInstance and the database being updated the TransactionScopeActivity is adorned with the PersistOnCloseAttribute. When the TransactionScopeActivity is used the WorkflowRuntime must be configured with a WorkflowPersistenceService. This could be the build in SqlWorkflowPersistenceService or another custom WorkflowPersistenceService.