How to load runnable instances with multiply workflow definitions from Instance Store when server restart

一世执手 提交于 2019-12-22 17:53:21

问题


I'm evaluating Workflow Foundation 4 or 4.5, and want to know how to load runnable instances with multiply workflow definitions from instance store when server restart?

It's same question as the forum topic: http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/b8d5ed34-054a-4e55-88e1-cd430ac42110?prof=required

"When using the InstanceStore.WaitForEvents, the HasRunnableWorkflowEvent event is raised if any instance is ready. And, to call the WorkflowApplication.LoadRunnableInstance (), we need to create a new WorkflowApplication, and it require the right workflow definition. It's easy when having only 1 workflow implementation. But, if there are multiples types of workflows associated with the same InstanceStore, and because the HasRunnableWorkflowEvent doesn't have any other informations on the ready instance that will be loaded by the LoadRunnableInstance (), we can't know what type of instance we must create for the new WorkflowApplication."

but the answer suggests:

The only way is to have a separate instance store for each workflow definition when hosting with WorkflowApplication.

Did I miss something?


回答1:


You can have multiple kind of workflow definitions in a single store but you need to keep track of which workflow definition you used to start the workflow. Which is your problem. In my current project we solved this using the following.

We use a wrapper class around the WorkflowApplication class, and use this to start the workflow. In this wrapper, before we actually start the workflow we write a WorkflowInstance record in a table in a database where we store the definition of the soon-to-be-running eorkflow. Aside from some other info, we also have a column for the 'persisted-id', which is the id generated by the WorkflowApplication object. We do not know this id when we start the workflow, so we leave this column empty. When the running workflow instance is persisted (which you can be notified of by handling an event on the WorkflowApplication object), you CAN retrieve the id generated by the WorkflowApplication object. Update your WorkflowInstance with the persisted-id, and when the workflow is to be reloaded upon a server restart, you can us the id to retrieve the workflowdefinition.

Hope this helps. Works like a charm here.



来源:https://stackoverflow.com/questions/12286813/how-to-load-runnable-instances-with-multiply-workflow-definitions-from-instance

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