locked
WorkflowApplication events RRS feed

  • General discussion

  • Hi All,

    It's not really a question but I don't have a blog, so I'd like to summarize it somewhere and share with the community. I didn't found any good summary on the callbacks of the WorkflowApplication class which describes the lifecycle of workflows so I made some experiments and here are the conclusions.

    The WorkflowApplication class can be used to host a workflow instance and execute it on multiple threads. Information on the status of the workflow can be gathered using a tracking participand and implementing certain call-back delegates that the WorkflowApplication can call. These are: Aborted, Completed, Idle, PersistableIdle, OnUnhandledException and Unloaded.

    Completed is called when a workflow gracefully completes, i.e. not aborted, see below. A workflow can complete various ways: canceled, faulted, closed. This information can be retrieved from the delegate arguments.

    The Idle delegate is called when the workflow, roughly said, inbetween two activities and can receive output from the outside. Available bookmarks are reported at this state.

    The OnUnhandledException delegate is called when... well, an unhandlen exception is thrown. The interesting part of this delegate is that it has to return a value that tells the workflow runtime how to proceed. Returning UnhandledExceptionAction.Abort will cause the workflow to abort and the Abort delegate will be called at the end. UnhandledExceptionAction.Cancel will cause the activity cancel, then stop gracefully (Completed and then Unloaded will be called). UnhandledExceptionAction.Terminate will cause the root activity of the workflow to complete gracefully, including clearing the persistence store (which Abort doesn't do, according to the docs.)

    The Unloaded delegate is called when the workflow is gracefully unloaded from memory (so didn't abort). At this point the workflow has not necessarily completed because it might have been just written to the persistence store.

    Aborted is called when an unhandled exception is thrown and the OnUnhandledException delegate returns UnhandledExceptionAction.Abort.

    The PersistableIdle delegate is called only when the WorkflowApplication has a persisentence store associated with and the workflow is in an idle stage and Unload or Persist is called on the WorkflowApplication. By returning the appropriate value, one can decide to persist the workflow (PersistableIdleAction.Persist), persist and unload it from memory (PersistableIdleAction.Unload) or do neither (PersistableIdleAction.None).

    So, a simple workflow execution will raise the following events:

    [Idle ...] [Completed] [Unloaded]

    A faulting workflow that is not aborted:

    [Idle ...] [OnUnhandledException] [Completed] [Unloaded]

    A faulting workflow that is aborted:

    [Idle ...] [OnUnhandledException] [Aborted]

    A persistable workflow that goes idle but not persisted:

    [Idle] [PersistableIdle] [Completed] [Unloaded]

    A persistable workflow that goes idle and gets persisted:

    [Idle] [PersitableIdle] [Unloaded]

    This workflow's not completed yet, has to be resumed from the persistence store and run again to complete.

    Please feel free to correct or complete this summary

    Saturday, August 4, 2012 4:06 PM