我有一个工作流,它会监视某些数据库,并在注意到触发器时启动其他工作流。我只希望这个“观察者”工作流的一个实例在任何时候都在运行;否则,如果两个或更多的实例正在运行,它们都会注意到更改,并且都会触发相同的工作流,这将不会很好地工作。
这个“观察者”工作流是持久化的。So...how我是不是应该这样做:如果运行时还没有持久化的工作流实例,它会启动一个,但如果已经有了,就使用持久化的实例?
听起来就像我可以创建一个运行一次的小型控制台应用程序来启动我想要的工作流,然后“真正的”运行时只是拉出持久化的应用程序,而从不尝试创建新的应用程序,但这听起来并不是很优雅。
发布于 2009-06-11 21:09:20
对于我目前正在工作的一个项目,我也在考虑这个问题。然而,在我看来,监视数据库的功能并不是工作流程的责任。
我们将创建一个Service来添加到运行时。此服务将引发工作流在HandleEventActivity中侦听的事件。这样,工作流程就会变得空闲,一直持续到真正的工作需要完成为止。
发布于 2009-06-11 15:11:33
不久前,我们在一个项目中遇到了这个问题。我们提出的解决方案是托管两个运行时;一个有持久性服务,另一个没有。在没有持久化服务的运行时,我们运行了几个这样的“监控工作流”,它们是在主机启动时自动启动的。
它是这样实现的:
首先,我们有一个配置文件,我们在其中设置了持久性服务:
<configuration>
<configSections>
<section name="RuntimeWithPersistence" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</configSections>
<RuntimeWithPersistence>
<CommonParameters/>
<Services>
<add type="System.Workflow.Runtime.Hosting.DefaultWorkflowSchedulerService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionString="[dbconnectionstring]" UnloadOnIdle="true"/>
</Services>
</RuntimeWithPersistence>
</configuration> 在工作流主机应用程序中(剪切和编辑,但我想我传达了我的想法):
public class WorkflowHost
{
private WorkflowRuntime _runtime = null;
private WorkflowRuntime _nonPersistingRuntime = null;
private void SetupRuntime()
{
// create a new WorkflowRuntime that points out a config section
// defining a persistence service
_runtime = new WorkflowRuntime("RuntimeWithPersistence");
// set up additional services to use
_runtime.StartRuntime()
// create a new WorkflowRuntime that does not point out a config section
_nonPersistingRuntime = new WorkflowRuntime();
// set up additional services to use
_nonPersistingRuntime.StartRuntime()
// start monitoring workflows in the non persisting runtime
StartMonitoringWorkflows(_nonPersistingRuntime);
}
}https://stackoverflow.com/questions/981690
复制相似问题