如何从内部取消或终止工作流程
我有一个在 ftp 站点之间移动文件的工作流程。 可能出现这样的情况:用户在工作流即将复制文件时从 ftp 站点删除文件。我可以检测到该文件已消失,因此我想取消即将进行文件传输的工作流程。
我使用工厂开始我的工作流程。工厂创建一个帮助程序类 (wfManager),该帮助程序类使用 WorkflowApplication 启动实际工作流程。
工作流程本身根据文件是否丢失来确定是否应该关闭。工作流引用了启动它的 wfManager,因此从 wfManager 调用workflowApplication.close
我原以为如果我使用 wfManager 中的 WorkflowApplication.close 工作流将关闭。
然而,关闭超时。
什么会导致关闭超时?是否有通用方法通过代码关闭或终止工作流程?
I have a workflow that moves files around between ftp sites.
It can be the case that a user deletes the files from an ftp site while the workflow is about to copy it. I can detect that the file is gone, so I want to Cancel the workflow about to do the file transfer.
I start my workflows using a factory. The factory creates a helper class (wfManager) and the helper class starts the actual workflow using WorkflowApplication.
The workflow itself determines if it should Close based on if the file has gone missing. The workflow has a reference to the wfManager that started it so calls workflowApplication.close from the wfManager
I had thought that if I use WorkflowApplication.close from the wfManager that the workflow would Close.
However, the Close times out.
What would cause the Close to time out and is there a generic way to close or terminate a workflow via code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您基本上有 3 个选项来结束工作流程:
取消
正如您所看到的,这会等待一段时间(以便工作流可以完成当前正在执行的任何操作),然后关闭工作流,然后调用 OnCompleted 处理程序
Terminate
这需要一个终止原因(作为参数),等待一段时间(以便工作流可以完成当前正在执行的任何操作),然后关闭工作流,然后调用 OnCompleted 处理程序
Abort
这只会终止工作流程并且不会调用 OnCompleted 处理程序。
MSDN 参考:
You have basically 3 options to end a worklflow:
Cancel
As you have seen this waits a bit of time (so the workflow can finish whatever it is currently doing), then closes the workflow, then invoke the OnCompleted handler
Terminate
This takes a reason for termination (as a param), waits a bit of time (so the workflow can finish whatever it is currently doing), then closes the workflow, then invoke the OnCompleted handler
Abort
This just kills the workflow and does not call OnCompleted handler.
MSDN references:
此外,您可以使用 TerminateWorkflow 活动从工作流内部终止工作流。
另请记住,WF4 中的所有内容都是异步的,如果工作流在某个活动中阻塞,则 Cancel() 调用将会超时,因为调度程序一次只会执行一项操作。
In addition you can terminate your workflow from inside of the workflow using a TerminateWorkflow activity.
Also keep in mind that everything in WF4 is asynchronous and if the workflow is blocking in an activity the Cancel() call will time out because the scheduler will only do one action at the time.
如果工作流决定自行取消,则有两个选项
在您的场景中,您应该使用终止活动。
尝试回调其他试图取消回调线程上的工作流的对象会导致灾难(正如您所发现的)。同样,您无法从任何委托处理程序或扩展取消工作流程。
If a workflow decides it wants to cancel itself there are two options
In your scenario you should use the Terminate activity.
Trying to call back to other objects that attempt to cancel the workflow on a callback thread is a recipe for disaster (as you found out). Likewise you cannot cancel the workflow from any delegate handler or extension.