开发者

Persistable Workflow with MVC - Run throwing exception on completed

开发者 https://www.devze.com 2023-02-20 07:55 出处:网络
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

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.


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();


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消