How can I handle the termination of a workflow?
I have implemented a queuing mechanism including UI for running specific types of workflows (WF 3.5), where I wanted to include a possibility for a user to cancel / terminate the workflow. The termination doesn't have to be synchronous, it would be enough to show that the cancellation is in progress and let him refresh the state later.
So far I have managed to simply use the workflow instance's function Terminate() to kill the workflow, which works perfectly and even synchronously, but it seems that it is not giving the workflow any chance to react to the termination. What I have tried was :
- Create a Cancellation handler at the level of the workflow, this was not executed.
- Create a Fault handler at the level of the workflow, with the fault type of WorkflowTerminatedException. This wasn't executed either.
Basically it seems that termination means really to immediately kill the workflow no matter what it is currently doing. Is there a way to :
- Handle the termination (with the Terminate() function) in any other way ? (maybe some settings which I've missed)
- Cancel the workflow externally in such a way that its cancellation handler or fault handle开发者_高级运维r are executed giving it the chance to tidy up etc. ?
Strangely enough, I was thinking about this earlier today.
Maybe you find this link useful: Stopping a build > Cancelling a workflow as its talks about a possible approach.
精彩评论