Windows从睡眠状态返回后的InstanceOwnerException

Windows从睡眠状态返回后的InstanceOwnerException,windows,workflow-foundation,workflow-foundation-4,Windows,Workflow Foundation,Workflow Foundation 4,也许你们中的任何人都能帮我解决这个问题。我有一个长时间运行的工作流,由一个长时间运行的应用程序使用 我使用SqlWorkflowInstanceStore进行持久化 我设置了DefaultInstanceOwner,以便在应用程序的另一次启动时重新加载工作流 InstanceHandle handle = workflowInstanceStore.CreateInstanceHandle(); InstanceView view = workflowInstanceStore.Execute(

也许你们中的任何人都能帮我解决这个问题。我有一个长时间运行的工作流,由一个长时间运行的应用程序使用
我使用SqlWorkflowInstanceStore进行持久化
我设置了DefaultInstanceOwner,以便在应用程序的另一次启动时重新加载工作流

InstanceHandle handle = workflowInstanceStore.CreateInstanceHandle();
InstanceView view = workflowInstanceStore.Execute(handle, 
                          new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));
handle.Free();
workflowInstanceStore.DefaultInstanceOwner = view.InstanceOwner;
我在应用程序退出时将其删除:

 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


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

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

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

非常有趣-如果我可以重现这一点,我想提交一个bug。你有一个简单的复制品我可以看一下吗?这里有同样的问题。您找到其他解决方案了吗?解决方案确实是在WorkflowInstanceOwner无效时检查系统恢复。