尝试使用以下代码恢复工作流时:
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;
}
看起来这段代码的工作时间有一半,但另一半却没有正确恢复它的工作流程。 有没有人知道我可以做些什么来正确地删除锁,而不必重新编写所有这些功能?
答案 0 :(得分:2)
请查看描述持久性和instaneStore配置的this blog post。
此代码是从帖子中复制的,我认为它可能对您有所帮助:“
var instanceStore = new SqlWorkflowInstanceStore(connStr);
var instanceHandle = instanceStore.CreateInstanceHandle();
var createOwnerCmd = new CreateWorkflowOwnerCommand();
var view = instanceStore.Execute(instanceHandle, createOwnerCmd, TimeSpan.FromSecond(30));
instanceStore.DefaultInstanceOwner = view.InstanceOwner;
// Do whatever needs to be dome with multiple WorkflowApplications
var deleteOwnerCmd = new DeleteWorkflowOwnerCommand();
instanceStore.Execute(instanceHandle, deleteOwnerCmd, TimeSpan.FromSeconds(30));
关键是需要在开始时执行的CreateWorkflowOwnerCommand。当您使用CreateWorkflowOwnerCommand时,请确保不要忘记DeleteWorkflowOwnerCommand,否则所有工作流将由所有者保持锁定状态,并且不能由另一个SqlWorkflowInstanceStore重新加载
答案 1 :(得分:0)
我在这里看不到instance.Run
或instance.ResumeBookmark
,并且你需要解决任何与执行相关的事件,例如PersistableIdle。
答案 2 :(得分:0)
实际上,当我在开发中看到这个错误时,它只意味着我需要清理我的持久性数据库。您可以使用已存在的存储过程来删除持久工作流。
答案 3 :(得分:0)
尝试制作WorkflowIdleBehavior
对象并将其TimeToUnload
设置为零。有关详细信息,请参阅here。