尝试使用以下代码恢复工作流时:
public WorkflowApplication LoadInstance(Guid instanceId)
{
if (this.instances.ContainsKey(instanceId))
return this.instances[instanceId];
WorkflowApplication instance = new WorkflowApplication(new Tarpon.Workflows.CreateContact());
// Create Persistable Workflow
SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(ConfigurationManager.ConnectionStrings["WorkflowPersistance"].ConnectionString);
store.HostLockRenewalPeriod = new TimeSpan(0, 0, 5);
instance.InstanceStore = store;
// Load Instance
instance.Completed += OnWorkflowCompleted;
instance.Idle += OnIdle;
instance.PersistableIdle += OnIdleAndPersistable;
instance.Aborted += OnAborted;
instance.Load(instanceId);
// Save instance in list of running instances
this.instances.Add(instance.Id, instance); // ERROR IS THROWN HERE
return instance;
}
我在“ this.instances.Add(instance.Id, instance) ”这一行得到错误:
The execution of an InstancePersistenceCommand was interrupted because the instance '9b9430b6-f182-469d-bcae-0886d546f7ea' is locked by a different instance owner.
This error usually occurs because a different host has the instance loaded. The instance owner ID of the owner or host with a lock on the instance is '30411662-b9b3-4250-9e2c-5aaa9895b740'.
我试图在上面的代码中降低 HostLockRenewalPeriod,并且还添加了下面的代码以希望禁用实例上的锁定,但无济于事。它似乎也永远不会闯入下面的代码。每次我通过 Load() 方法时,都会出现上述错误。
public PersistableIdleAction OnIdleAndPersistable(WorkflowApplicationIdleEventArgs e)
{
instances.Remove(e.InstanceId);
return PersistableIdleAction.Unload;
}
这段代码似乎有一半的时间可以工作,但另一半却没有正确恢复它的工作流程。有没有人知道我可以做些什么来正确删除锁,而不必重新编写所有这些功能?