0

尝试使用以下代码恢复工作流时:

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

这段代码似乎有一半的时间可以工作,但另一半却没有正确恢复它的工作流程。有没有人知道我可以做些什么来正确删除锁,而不必重新编写所有这些功能?

4

4 回答 4

2

请查看这篇描述持久性和 instaneStore 配置的博客文章。

此代码是从帖子中复制的,我认为它可能会对您有所帮助:“

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 重新加载

于 2012-09-13T10:05:17.630 回答
0

我没有看到instance.Runinstance.ResumeBookmark在这里,您需要它来触发任何与执行相关的事件,例如 PersistableIdle。

于 2012-05-24T21:52:46.077 回答
0

实际上,当我在开发中看到这个错误时,它只是意味着我需要清理我的持久性数据库。您可以使用已经存在的存储过程来删除持久化的工作流。

于 2012-06-04T11:51:27.493 回答
0

尝试制作一个WorkflowIdleBehavior对象并将其设置TimeToUnload为零。有关更多详细信息,请参见此处

于 2012-06-17T01:52:36.860 回答