我们有一个系统使用“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();
答案 0 :(得分:0)
您可以尝试使用 application.Unload(),这将帮助您解决 Abort 异常。默认情况下,卸载操作必须在 30 秒内完成。但是,如果它没有发生,则会触发 Abort 事件。