Compartilhar via


Persistence Host Sample

Download sample

This sample demonstrates how to persist a running workflow to disk when an application shuts down, and how to automatically reload a workflow by sending it an event.

The sample consists of a Windows Forms application that enables the user to create and start a workflow, and send an event to a running workflow. To send an event to a workflow, right-click the workflow in the list and then click Approve Document. Because the workflow has a HandleExternalEventActivity activity as its last activity, sending a message to the workflow causes the workflow to exit.

When the application shuts down, any running workflows are persisted to disk using the FilePersistenceService that is provided. An index of the running workflows is saved to an XML file. When the application restarts, the XML file is read to determine what workflows are still in progress, but the workflows themselves are not reloaded at this point. When events are sent to these workflows, the runtime automatically reloads them from disk and delivers the message, causing the workflow to finish.

To build the sample

  1. Download the sample by clicking Download Sample.

    This extracts the sample project to your local hard disk.

  2. Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.

  3. Go to the source directory of the sample.

  4. At the command prompt, type MSBUILD PersistenceHost.sln

To run the sample

  1. In the SDK Command Prompt window, run the .exe file in the HostApplication\bin\debug folder (or the HostApplication\bin folder for the Visual Basic version of the sample), which is located below the main folder for the sample.

See Also

Other Resources

Hosting Samples

© 2007 Microsoft Corporation. All rights reserved.