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 秒)。 此参数是一个可选参数。

适用于