Listing Currently Running Workflows in .Net 4.0

荒凉一梦 提交于 2020-01-01 17:37:12

问题


I've got a .Net 4.0 Workflow application hosted in WCF that takes a request to process some information. This information is passed to a secondary system via a web service and returns a bool indicating that its going to process that information.

My workflow then loops, sleeping for 5 minutes and then querying the secondary system to see if processing of the information is complete.

When its complete the workflow finishes.

I have this persisting in SQL, and it works perfectly.

My question is how do I retrieve a list of the persisted workflows in such a way that I can tie them back to the original request? I'd like my UI to be able to list the running workflows in a grid with the elapsed time that they've been run.

I've thought about storing the workflow GUID in my primary DB and generating the list that way, but what I'd really like is to be able to reconcile what I think is running, and what the persistant store thinks is running.

I'd also like to be able to select a running workflow and kill it off or completely restart it if the user determines that its gone screwy.


回答1:


You can promote data from the workflow using the SqlWorkflowInstanceStore. The result is they are stored alongside the workflow data in the InstancesTable using the InstancePromotedPropertiesTable. Using the InstancePromotedProperties view is the easiest way of querying you data.

This blog post will show you the code you need.




回答2:


Another option, use the WorkflowRuntime GetAllServices(). Then you can loop through each one to pull out the data you need. I would cache the results, given this may be an expensive operation. If you have only 100 or less running workflows, and only a few users on your page, don't bother caching.

This way you don't have to create a DAL or Repo layer. Especially if you are using sql for persistence.

http://msdn.microsoft.com/en-us/library/ms594874(v=vs.100).aspx



来源:https://stackoverflow.com/questions/3560387/listing-currently-running-workflows-in-net-4-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!