0

我们有一个使用“WWF”作为其工作流引擎的系统,并且继续进行工作流的请求经常失败,并且日志中充满了这个异常。

System.Runtime.DurableInstancing.InstancePersistenceException:数据库中不存在 SqlWorkflowInstanceStore 锁。发生这种情况的原因可能是 SQL Server 正忙或连接暂时丢失。

并在此触发,event (application.Aborted = (e) =>{})有关如何解决此问题的任何想法?

这是我加载工作流程并释放锁的方式

            //Create an instance of the workflow and its application and associate with workflow application.
            Activity workflow = Activator.CreateInstance(workflowType) as Activity;
            WorkflowApplication application = new WorkflowApplication(workflow);
            application.SynchronizationContext = SyncSynchronizationContext.SingletonInstance;

            //Hold the workflow store            
            application.InstanceStore = CreateInstanceStore(WorkflowDatabaseConnectionString);
            var instanceHandle = application.InstanceStore.CreateInstanceHandle(guid);
            var ownerCommand = new CreateWorkflowOwnerCommand();
            var view = application.InstanceStore.Execute(instanceHandle, ownerCommand, TimeSpan.FromDays(30));

            application.InstanceStore.DefaultInstanceOwner = view.InstanceOwner;
            // Do whatever needs to be dome with multiple WorkflowApplications

            if (pParticipant != null)
                application.Extensions.Add(pParticipant);

            //Register workflow application services from the external world
            ExternalRegisteredServices.ForEach(service => application.Extensions.Add(service));

            ReadOnlyCollection<BookmarkInfo> currentBookmarks = null;
            Dictionary<string, object> wfContextBag = null;

            application.PersistableIdle = (workflowApplicationIdleEventArgs) =>
            {
                currentBookmarks = workflowApplicationIdleEventArgs.Bookmarks;

                wfContextBag = workflowApplicationIdleEventArgs
                    .GetInstanceExtensions<WorkflowContext>()
                    .First()
                    .GetBag();
                return PersistableIdleAction.Unload;
            };

            application.OnUnhandledException = (e) =>
            {
                if (wfUnhandledExceptionEventHandler != null)
                    wfUnhandledExceptionEventHandler(e);
                return UnhandledExceptionAction.Abort;
            };

            application.Aborted = (e) =>
            {
                if (wfAbortedEventHandler != null)
                    wfAbortedEventHandler(e);
            };

            application.Completed = (e) =>
            {
                if (wfCompletedEventHandler != null)
                    wfCompletedEventHandler(e);
            };

            application.Load(guid);

            BookmarkResumptionResult resumptionResult = BookmarkResumptionResult.NotFound;
            if (!string.IsNullOrEmpty(bookmarkName))
                resumptionResult = application.ResumeBookmark(bookmarkName, null);

            if (resumptionResult != BookmarkResumptionResult.Success)
                currentBookmarks = application.GetBookmarks();

            var deleteOwnerCommand = new DeleteWorkflowOwnerCommand();
            application.InstanceStore.Execute(instanceHandle, deleteOwnerCommand, TimeSpan.FromSeconds(30));
            instanceHandle.Free();
4

1 回答 1

0

您可以尝试使用 application.Unload(),这将帮助您解决 Abort 异常。默认情况下,卸载操作必须在 30 秒内完成。但是,如果没有发生,则会触发 Abort 事件。

于 2021-03-08T18:57:55.230 回答