简体   繁体   中英

Why doesn't the Workflow wake up after being unloaded?

I'm trying to understand the .NET Workflow Foundation a bit better, especially how the persist / unload and resume functionality works.

So for test purposes I created a very simple Activity and attempted to host it in a WorkflowApplication . I'd like to learn how to use the ability to persist the workflow instances when they are idle. So I wrote the following code:

var store = new SqlWorkflowInstanceStore("......");
var identity = new WorkflowIdentity("MyAwesomeWorkflow", Version.Parse("1.0"), String.Empty);
var activity = new Sequence()
{
    Activities =
    {
        new WriteLine() {Text = "hello"},
        new Delay() {Duration = TimeSpan.FromSeconds(5)},
        new WriteLine() {Text = "bye"},
    }
};
var wfapp = new WorkflowApplication(activity, identity);
var resetEvent = new ManualResetEventSlim();
wfapp.InstanceStore = store;
wfapp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
{
    Console.WriteLine("Persistable idle");
    return PersistableIdleAction.Unload;
};
wfapp.Completed += delegate(WorkflowApplicationCompletedEventArgs eventArgs)
{
    Console.WriteLine("completed");
    resetEvent.Set();
};

wfapp.Run();
resetEvent.Wait();

The workflow is unloaded when the Delay Activity starts, but it is not resumed when the Delay is over. I'm not a Workflow Foundation expert, so I realize I must be using the API incorrectly. According to my collegaues, the Workflow should automatically wake up and resume execution when the Delay is over.

I've read this MSDN article on the topic but it doesn't seem to explain this aspect very well.

In the meantime I've figured it out. Since nobody has posted an answer, I'll just post it here just in case somebody is looking for a solution.

Basically, the Workflow Engine does not support automatic resumption of workflow instances. It is misleading somewhat, but WorkflowApplication does not support this.

So you could:

  • Manually poll the instance store database and resume the workflow instances when appropriate
  • Use WorkflowServiceHost which implements the same polling under the hood

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM