Is there a way to exit a workflow more gracefully than throwing an InvalidWorkflowException
? I'm writing an activity (that interacts with an SQL database) that needs to short-circuit if an opera开发者_JAVA百科tion fails.
I know it could be split it up into multiple steps/activities and chain them, but could I set the state of my execution from within an activity?
Something like this.currentContext.SetState(Cancelled)
?
I think it really comes down to how you have your workflow laid out. If this is not an exceptional case, then go ahead and handle it in your work flow. You could set a property and then end that task. The next task can be a decision task to decide whether you stop all processing or go on to subsequent steps.
If it is an exceptional case then you should throw an exception and let all the compensation logic do its thing.
I'm honestly not sure as I'm relatively new to using Windows Workflow, but what about using a NativeActivity
and looking at NativeActivityContext.CancelChildren
?
Look too at this article on MSDN: Modeling Cancellation Behavior in Workflow.
I think it is the same situation as in any other program. You will throw some exception if error occures in your activity and you will use try/catch activity to handle it and terminate WF gracefully.
精彩评论