Custom workflow activities and the PersistOnClose attribute

If you are developing your own workflow activities 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 workflow runtime 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 work batch might be your friend. With a work batch the actual work is postponed until the workflow reached a persistence point. And the end of the workflow is always a persistence point [:)]


Leave a Reply

Your email address will not be published. Required fields are marked *