使用 MVC 的持久工作流 - 运行完成时抛出异常

发布于 2024-10-27 01:36:15 字数 1219 浏览 2 评论 0原文

我在 MVC 3 应用程序中运行持久工作流,运行良好,但当工作流完成时,会引发 WorkflowApplicationCompletedException。工作流程已成功完成,最后的操作已完成,实例已从数据库中删除。

到目前为止,我还没有找到答案,因此任何导致异常的想法将不胜感激。我当前的解决方法是捕获异常并为 OnCompleted-Event 执行我的操作。

我只是创建一个 WorkflowApplication,加载它并恢复书签。

任何提示或建议表示赞赏。 谢谢

application.Load(new Guid(basket.StandardFields.Settings));
application.ResumeBookmark(application.GetBookmarks().First().BookmarkName, WorkflowInputs);


application.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
{
    if (e.Bookmarks != null && e.Bookmarks.Count > 0)
    {
        _viewName = e.Bookmarks[0].BookmarkName;
    }

    syncContext.OperationCompleted();
    return PersistableIdleAction.Unload;
};

application.Completed = delegate (WorkflowApplicationCompletedEventArgs e)
{
    CompleteWorkflow(syncContext);
};

application.SynchronizationContext.OperationStarted();

try
{
    application.Run();
}
catch(WorkflowApplicationCompletedException)
{
    CompleteWorkflow(syncContext);
}

编辑

似乎 application.ResumeBookmark(bookmark, WorkflowInputs) 启动工作流程并完成活动,然后当我调用 run 时,它抱怨它已经完成。但是,如果我在调用恢复工作流时不调用运行,则浏览器永远不会获取任何信息,并且我认为它会无休止地等待,因为即使刷新也无法将其从等待状态中唤醒。

I'm running a persistable Workflow in an MVC 3 Application, which is working out well, but when the workflow is completed, a WorkflowApplicationCompletedException is thrown. The Workflow is completed sucessfully, the last actions done and the instance deleted from the database.

I've had no luck searching for an answer so far, so any ideas what is causing the exception would be appreciated. My current workaround is catching the exception and doing my stuff there for the OnCompleted-Event.

I'm simply creating a WorkflowApplication, loading it and resuming the bookmark.

Any hints or suggestions appreciated.
Thanks

application.Load(new Guid(basket.StandardFields.Settings));
application.ResumeBookmark(application.GetBookmarks().First().BookmarkName, WorkflowInputs);


application.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
{
    if (e.Bookmarks != null && e.Bookmarks.Count > 0)
    {
        _viewName = e.Bookmarks[0].BookmarkName;
    }

    syncContext.OperationCompleted();
    return PersistableIdleAction.Unload;
};

application.Completed = delegate (WorkflowApplicationCompletedEventArgs e)
{
    CompleteWorkflow(syncContext);
};

application.SynchronizationContext.OperationStarted();

try
{
    application.Run();
}
catch(WorkflowApplicationCompletedException)
{
    CompleteWorkflow(syncContext);
}

Edit

It seems that the application.ResumeBookmark(bookmark, WorkflowInputs) starts the Workflow and Completes the activities, then when I call run, it complains the it's already completed. But if I don't call run when resume workflow is called, the browser never gets any information and I think it stays waiting endlessly cause not even a refresh can knock it out of the waiting state.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乖乖哒 2024-11-03 01:36:15

看来使用 ResumeBookmark 后就不需要再调用 Run 了。我想我之前在错误的地方做了这件事,所以工作流程变得混乱,但现在似乎工作正常。

if(hasWorkflow)
    application.ResumeBookmark(application.GetBookmarks().First().BookmarkName, WorkflowInputs);
else
    application.Run();

It seems that with ResumeBookmark there is no need to call Run afterwards. I think I was doing it at the wrong place before and so the workflow got messed up, but it seems to be working fine now.

if(hasWorkflow)
    application.ResumeBookmark(application.GetBookmarks().First().BookmarkName, WorkflowInputs);
else
    application.Run();
不念旧人 2024-11-03 01:36:15

MSDN

代表的异常是
对工作流程进行操作时抛出
实例无效,因为
实例已完成。

您显示的代码似乎有效。但是,您正在尝试恢复已进入完成状态的工作流程。您应该检查任何项目的Completed 属性您尝试恢复的工作流程。抛出一个 InvalidOperationException,你就会看到这是哪里发生的。

如果这不能确定问题所在,您的工作流程可能无法正确添加书签。该代码位于创建书签的活动中,所以我无法判断它是否正确完成......

MSDN:

Represents the exception that is
thrown when an operation on a workflow
instance is not valid because the
instance has completed.

The code you show appears valid. However, somewhere you are attempting to resume a workflow that has entered the completed state. You should be checking the Completed property of any Workflow you are attempting to resume. Thrown an InvalidOperationException and you'll see where this is happening.

If this doesn't identify where the problem is, your workflow may not be bookmarking properly. That code is in the activity that is creating the bookmark, so I can't tell if it is being done correctly...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文