語言

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。

範例

以下程式碼範例示範在 . 中使用 RunnableInstancesDetectionPeriod SqlWorkflowInstanceStore的應用。

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 秒)。 此參數為可選參數。

適用於