Persist On Close
Last changed: -


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