Windows从睡眠状态返回后出现InstanceOwnerException

时间:2011-12-06 12:47:46

标签: windows workflow-foundation workflow-foundation-4

也许你们中的任何人都可以帮助我解决这个烦人的问题。我有长时间运行的工作流程,由长时间运行的应用程序使用。
我使用SqlWorkflowInstanceStore来实现持久性。
我设置了DefaultInstanceOwner,这样我就可以在应用程序的另一个启动时重新加载工作流程。

InstanceHandle handle = workflowInstanceStore.CreateInstanceHandle();
InstanceView view = workflowInstanceStore.Execute(handle, 
                          new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));
handle.Free();
workflowInstanceStore.DefaultInstanceOwner = view.InstanceOwner;

我在app退出处将其删除:

 var deleteOwnerCmd = new DeleteWorkflowOwnerCommand();
 InstanceHandle handle = workflowInstanceStore.CreateInstanceHandle();
 workflowInstanceStore.Execute(handle, deleteOwnerCmd, TimeSpan.FromSeconds(30));
 handle.Free();

在正常的应用使用情况下一切顺利。如果Windows进入睡眠模式,则会出现此问题。当它从睡眠模式返回时,使用workflowInstanceStore的任何其他操作都会抛出:

System.Runtime.DurableInstancing.InstanceOwnerException: The execution of an InstancePersistenceCommand was interrupted because the instance owner registration for owner ID 'GUID' has become invalid. This error indicates that the in-memory copy of all instances locked by this owner have become stale and should be discarded, along with the InstanceHandles. Typically, this error is best handled by restarting the host.

我在LockOwnersTable中查看了数据库,并在系统唤醒时将锁定到期时间设置为2000-01-01 00:00:00.000。

欢迎任何找到此行为或变通方法的根本原因的想法。我已经采取了第一种解决方法,即禁用睡眠模式......

1 个答案:

答案 0 :(得分:1)

我认为这种行为的原因是,工作流实例存储应该告诉数据库它仍然以常规时间间隔(由HostLockRenewalPeriod属性定义)被存在。当计算机处于睡眠模式时,它无法更新LockOwnersTable的LockExpiration列,并且工作流实例存储被视为已不存在。

解决方案是在计算机从睡眠模式恢复时重新启动实例存储。 您可以通过注册Microsoft.Win32.SystemEvents.PowerModeChanged事件来检测这一点。