退出工作流程?
有没有比抛出 InvalidWorkflowException 更优雅地退出工作流程的方法?我正在编写一个活动(与 SQL 数据库交互),如果操作失败则需要短路。
我知道它可以将其分成多个步骤/活动并将它们链接起来,但是我可以在活动中设置执行状态吗?
像 this.currentContext.SetState(Cancelled)
这样的东西?
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 operation 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)
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这实际上取决于您如何安排工作流程。如果这不是特殊情况,请继续在您的工作流程中处理它。您可以设置一个属性,然后结束该任务。下一个任务可以是决策任务,用于决定是停止所有处理还是继续执行后续步骤。
如果是特殊情况,那么您应该抛出异常并让所有补偿逻辑执行其操作。
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.
老实说,我不确定,因为我对使用 Windows 工作流还比较陌生,但是使用
NativeActivity
并查看NativeActivityContext.CancelChildren
怎么样?另请参阅 MSDN 上的这篇文章:建模工作流中的取消行为。
I'm honestly not sure as I'm relatively new to using Windows Workflow, but what about using a
NativeActivity
and looking atNativeActivityContext.CancelChildren
?Look too at this article on MSDN: Modeling Cancellation Behavior in Workflow.
我认为这与任何其他程序的情况相同。如果您的活动中发生错误,您将抛出一些异常,并且您将使用 try/catch 活动来处理它并优雅地终止 WF。
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.