0

I have a workflow that runs (hosted by WorkflowApplication), sends an email, then persists using a bookmark. The email has a link that allows the workflow to resume at that bookmark, which it does properly. However, after the workflow finishes, the webpage never loads.

It's like the page is waiting for the workflow to finish but it never does. I am very new to workflow and even newer to multithreading, so my question is:

Is there anything special I need to do to exit the workflow completely so control is given back to the main thread? Like a delegate method I'm missing?

Cheers

4

1 回答 1

0

所以我在发帖后就想通了,所以我很抱歉。不过,这里是:

因为工作流在一个单独的线程上,所以它一旦完成就不会与主线程同步。所以我需要在 Completed 委托中添加一个方法,以确保它在完成后与主线程同步。我只是忘记了。希望这可以帮助某人。

首先,您需要设置和自动重置事件和一个 WorkflowApplication 对象

 private static AutoResetEvent _syncEvent = new AutoResetEvent(false);
 private static WorkflowApplcation _wfApp = new WorkflowApplication(new MyActivity());

然后在 wfApp 的委托方法中,确保调用:

 _syncEvent.Set();

所以:

wfApp.Completed = (e) =>
              {
                Debug.WriteLine("Workflow completed: {0}", e.Outputs["Message"]);
                _syncEvent.Set();
              };

最后一部分是我所缺少的

于 2012-07-18T20:16:05.460 回答