SqlWorkflowInstanceStore.RunnableInstancesDetectionPeriod 属性

定义

指定时间段,在该时间段后,SQL 工作流实例存储区将运行一个检测任务,来检测上一检测周期后持久性数据库中的任何可运行或可激活的工作流实例。

public:
 property TimeSpan RunnableInstancesDetectionPeriod { TimeSpan get(); void set(TimeSpan value); };
public TimeSpan RunnableInstancesDetectionPeriod { get; set; }
member this.RunnableInstancesDetectionPeriod : TimeSpan with get, set
Public Property RunnableInstancesDetectionPeriod As TimeSpan

属性值

返回 TimeSpan

示例

下面的代码示例演示如何在 SqlWorkflowInstanceStore 中使用 RunnableInstancesDetectionPeriod。

static void Main(string[] args)
{
    // Create service host.
    WorkflowServiceHost host = new WorkflowServiceHost(new CountingWorkflow(), new Uri(hostBaseAddress));

    // Add service endpoint.
    host.AddServiceEndpoint("ICountingWorkflow", new BasicHttpBinding(), "");

    // Define SqlWorkflowInstanceStoreBehavior:
    //   Set interval to renew instance lock to 5 seconds.
    //   Set interval to check for runnable instances to 2 seconds.
    //   Instance Store does not keep instances after it is completed.
    //   Select exponential back-off algorithm when retrying to load a locked instance.
    //   Instance state information is compressed using the GZip compressing algorithm.
    SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior(connectionString);
    instanceStoreBehavior.HostLockRenewalPeriod = new TimeSpan(0, 0, 5);
    instanceStoreBehavior.RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 2);
    instanceStoreBehavior.InstanceCompletionAction = InstanceCompletionAction.DeleteAll;
    instanceStoreBehavior.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry;
    instanceStoreBehavior.InstanceEncodingOption = InstanceEncodingOption.GZip;
    host.Description.Behaviors.Add(instanceStoreBehavior);

    // Open service host.
    host.Open();

    // Create a client that sends a message to create an instance of the workflow.
    ICountingWorkflow client = ChannelFactory<ICountingWorkflow>.CreateChannel(new BasicHttpBinding(), new EndpointAddress(hostBaseAddress));
    client.start();

    Console.WriteLine("(Press [Enter] at any time to terminate host)");
    Console.ReadLine();
    host.Close();
}

注解

SqlWorkflowInstanceStore 运行一个内部任务,该任务将定期苏醒并检查持久性数据库中是否存在任何可运行的实例。 如果实例不处于挂起状态或已完成状态,并且满足以下条件,则实例 可运行

  • 实例处于解除锁定状态,并且具有已过期的挂起计时器。

  • 实例处于解除锁定状态,并且其状态为“正在执行”。

  • 实例上的锁已过期。

当 SQL 工作流实例存储在数据库中找到可运行的实例并同时找到能够加载在计算机上运行的实例的工作流宿主时,它将引发 HasRunnableWorkflowEvent

当工作流宿主收到此事件时,它将针对实例存储执行 TryLoadRunnableWorkflowCommand,以将该实例加载到内存中。

属性的类型为 TimeSpan,值的格式为“hh:mm:ss”。 最小值为“00:00:01” (1 秒) 。 如果省略,则默认为“00:00:05” (5 秒) 。 此参数为可选参数。

适用于