Raise Event to Load Workflow Sample

Download sample

To send a document for approval, the workflow in this sample uses the CallExternalMethodActivity activity bound to the RequestDocumentApproval method of the DocumentApprovalInterface. The next activity in the workflow is a HandleExternalEventActivity activity that handles a DocumentApproved event.

The runtime is configured to unload workflow instances whenever the workflow is in the idle state, that is, when there is no work to be done for the instance. This is an important feature because the HandleExternalEventActivity activity might wait for a long time (maybe days or weeks) for the document approval.

The DocumentApprovalInterface defines the methods and events for sending and receiving document approvals. The DocumentApprovalService class implements the DocumentApprovalInterface to proxy method calls and event handling that flow data in and out of the workflow and host application.

The workflow initiates the document-approval process by sending a document for approval through the RequestDocumentApproval method that then delivers the document to the target (not implemented). The host OnWorkflowIdled event handler is called when the workflow becomes idle. At the same time, the runtime unloads the workflow instance through the FilePersistenceService. In the WorkflowIdled handler, we raise the DocumentApproved event to the workflow. The DocumentApproved event is delivered to the HandleExternalEventActivity documentApprovedInvoked handler.

The sample also uses a custom persistence service (FilePersistenceService) that serializes workflow state to a file.

When you build and run the application, your output will appear similar to the following:

Raise Event to load a workflow

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

To run the sample

  1. In the SDK Command Prompt window, run the .exe file in the DocumentApprovalWorkflow\bin\debug folder (or the DocumentApprovalWorkflow\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.