共用方式為


SqlWorkflowInstanceStore.InstanceLockedExceptionAction 屬性

定義

指定持續性提供者攔截 InstanceLockedException 時要執行的動作。

public:
 property System::Activities::DurableInstancing::InstanceLockedExceptionAction InstanceLockedExceptionAction { System::Activities::DurableInstancing::InstanceLockedExceptionAction get(); void set(System::Activities::DurableInstancing::InstanceLockedExceptionAction value); };
public System.Activities.DurableInstancing.InstanceLockedExceptionAction InstanceLockedExceptionAction { get; set; }
member this.InstanceLockedExceptionAction : System.Activities.DurableInstancing.InstanceLockedExceptionAction with get, set
Public Property InstanceLockedExceptionAction As InstanceLockedExceptionAction

屬性值

持續性提供者攔截 InstanceLockedException 時要執行的動作。

範例

下列程式碼範例將示範如何在 SqlWorkflowInstanceStore 中使用 InstanceLockedExceptionAction。

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();
}

備註

指定當工作流程服務執行個體發生 InstanceLockedException 時,服務主機應執行的動作。 當服務主機嘗試鎖定已由其他擁有人鎖定的執行個體時,服務主機會收到 InstanceLockedException。 以下清單列出可能的值:

  • None: 服務主機不會嘗試鎖定執行個體,以及傳遞 InstanceLockedException 至呼叫端。

  • BasicRetry。 服務主機以線性重試間隔,重新嘗試鎖定執行個體,並將例外狀況傳遞至位於順序結尾的呼叫端。

  • AggressiveRetry。 服務主機以指數遞增延遲,重新嘗試鎖定執行個體,並將 InstanceLockedException 傳遞至位於順序結尾的呼叫端。 一開始的間隔會很短暫,以期盡快取得鎖定,隨著每次嘗試失敗,間隔會越來越大。

適用於