试图恢复在Windows工作流时出错 [英] Error when attempting to Resume a Windows Workflow

查看:399
本文介绍了试图恢复在Windows工作流时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在试图恢复与以下code一个工作流程:

 公共WorkflowApplication LoadInstance(GUID实例Id)
    {
        如果(this.instances.ContainsKey(实例Id))
            返回this.instances [实例Id]        WorkflowApplication实例=新WorkflowApplication(新Tarpon.Workflows.CreateContact());        //创建持久化工作流程
        SqlWorkflowInstanceStore店=新SqlWorkflowInstanceStore(ConfigurationManager.ConnectionStrings[\"WorkflowPersistance\"].ConnectionString);
        store.HostLockRenewalPeriod =新时间跨度(0,0,5);
        instance.InstanceStore =店;        //装载实例
        instance.Completed + = OnWorkflowCompleted;
        instance.Idle + =的OnIdle;
        instance.PersistableIdle + = OnIdleAndPersistable;
        instance.Aborted + = OnAborted;
        instance.Load(实例Id);        在运行的实例列表//保存实例
        this.instances.Add(instance.Id,实例); //引发错误HERE        返回实例;
    }

我得到和上线错误 this.instances.Add(instance.Id,实例)

 的InstancePersistenceCommand的执行被中断,因为实例9b9430b6-f182-469d-bcae-0886d546f7ea'是由不同的实例所有者锁定。
通常会出现此错误,因为不同的主机具有加载的实例。所有者或主机的实例锁的实例所有者ID为30411662-b9b3-4250-9e2c-5aaa9895b740。

我试图降低上述code中的HostLockRenewalPeriod,并且还增加了以下code到希望禁用的实例,但无济于事锁。这也似乎从来没有打入低于code。每次我走过去的Load()方法,我得到日上述错误。

 公共PersistableIdleAction OnIdleAndPersistable(WorkflowApplicationIdleEventArgs E)
    {
        instances.Remove(e.InstanceId);
        返回PersistableIdleAction.Unload;
    }

看来这code工作一半时间,而另一半没有恢复它正确的工作流程。
没有人有任何线索,我能做些什么才能正常解除锁定,而无需重新编写所有这些功能?


解决方案

请看看<一个href=\"http://msmvps.com/blogs/theproblemsolver/archive/2009/11/19/windows-workflow-foundation-4-and-persistence.aspx\"相对=nofollow>这个博客帖子描述的持久性和instaneStore confiuration。

这code是从复制后,我认为它可以帮助你:

  VAR instanceStore =新SqlWorkflowInstanceStore(connStr);
变种instanceHandle = instanceStore.CreateInstanceHandle();
VAR createOwnerCmd =新CreateWorkflowOwnerCommand();
VAR视图= instanceStore.Execute(instanceHandle,createOwnerCmd,TimeSpan.FromSecond(30));
instanceStore.DefaultInstanceOwner = view.InstanceOwner;
//做任何需要有圆顶多WorkflowApplications
VAR deleteOwnerCmd =新DeleteWorkflowOwnerCommand();
instanceStore.Execute(instanceHandle,deleteOwnerCmd,TimeSpan.FromSeconds(30));


  

的关键是需要在开始要执行的CreateWorkflowOwnerCommand。而当你使用CreateWorkflowOwnerCommand只是要确保不要忘记DeleteWorkflowOwnerCommand否则,所有的工作流程会由业主保持锁定状态,不能被其他SqlWorkflowInstanceStore重新加载


When attempting to Resume a Workflow with the following code:

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

I get and error on the line "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'.

I have attempted to lower the HostLockRenewalPeriod in the above code, and also added the below code to hopefully disable the lock on the Instance but to no avail. It also never seems to break into the below code. Every time I go past the Load() method, I get th above error.

    public PersistableIdleAction OnIdleAndPersistable(WorkflowApplicationIdleEventArgs e)
    {
        instances.Remove(e.InstanceId);
        return PersistableIdleAction.Unload;
    }

It seems this code works half the time, but the other half it does not resume it's workflows correctly. Does anyone have any clue to what I can do to remove the lock properly, without having to re-write all of this functionality?

解决方案

Please take a look at this blog post describing persistance and instaneStore confiuration.

This code is copied from the post and I think it might help you: "

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

The key is the CreateWorkflowOwnerCommand that needs to be executed at the start. And when you use the CreateWorkflowOwnerCommand just make sure not to forget the DeleteWorkflowOwnerCommand otherwise all workflow will remain locked by the owner and can’t be reloaded by another SqlWorkflowInstanceStore

这篇关于试图恢复在Windows工作流时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆