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。 以下列表中列出了可能的值:

  • 。 服务主机不会尝试锁定实例,并将 InstanceLockedException 传递给调用方。

  • BasicRetry。 服务主机将使用线性重试间隔重新尝试锁定实例,并在序列结尾将异常传递给调用方。

  • AggressiveRetry。 服务主机将使用按指数增长的延迟时间重新尝试锁定实例,并在序列结尾将 InstanceLockedException 传递给调用方。 在开始尽可能快地尝试获取锁定时,这些间隔很短,而且每次尝试不成功后,这些间隔将增大。

适用于