Export (0) Print
Expand All

EventArgs Tracking Sample 

Download sample

This sample demonstrates the use of the SQL tracking service that is provided by Windows Workflow Foundation to track the execution of a workflow.

The workflow runtime raises certain events while it is executing a workflow. The tracking service can catch these events and store information about them in a SQL Server database that can be queried.

The tracking runtime defines TrackingWorkflowTerminatedEventArgs, TrackingWorkflowSuspendedEventArgs, and TrackingWorkflowExceptionEventArgs types to hold information about workflow termination, suspension, and exceptions respectively. WorkflowEventArgs are sent with the WorkflowTrackingRecord for their corresponding events. For example, TrackingWorkflowTerminatedEventArgs are sent with WorkflowTrackingRecord when the workflow status reaches a WorkflowTerminated state.

The SqlTrackingService receives these various EventArgs objects as they arrive, serializes them, and saves them to the tracking database together with their events if the tracking profile asks for those events. The serialized form can then be deserialized and consumed by tracking users. The tracking profile that is used is the SqlTrackingService default tracking profile.

NoteNote

The time value in a WorkflowTrackingRecord is in Coordinated Universal Time (Greenwich Mean Time).

Sample Overview

The sample is a workflow console application and consists of two workflows:

  • ExceptionWorkflow. A simple workflow with a code handler, in which an exception is thrown. The exception is unhandled and results in terminating the workflow.

  • SuspendedWorkflow. A simple workflow with a suspend activity. The workflow should reach a suspended state.

The main entry for the sample is in the Program class, which has the following logic:

  1. Creates a connectionString to the SqlTrackingService database.

  2. Adds SqlTrackingService to the workflow runtime as follows:

    workflowRuntime.AddService(new SqlTrackingService(connectionString));
    
  3. Runs the workflows as follows:

    WorkflowInstance exceptionWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(ExceptionWorkflow));
    exceptionWorkflowInstance.Start();
    
  4. Creates event handlers to wait for the workflow to finish or terminate (depending on the type of the workflow).

  5. Queries the SqlTrackingService for specific WorkflowEvents and retrieves the binary-serialized object of the TrackingWorkflowTerminatedEventArgs, TrackingWorkflowSuspendedEventArgs, and TrackingWorkflowExceptionEventArgs.

  6. Deserializes the data and writes their contents to the console.

Creating the SqlTrackingService Database

The SQL services that are installed by Windows Workflow Foundation use Microsoft SQL Server to store information. You can use Microsoft SQL Server 2005 Express, SQL Server 2000 or later versions, or SQL Server 2000 Desktop Engine (MSDE) for these tasks.

Windows Workflow Foundation Setup does not install the databases that are required by these services; however, Setup installs the SQL scripts for creating and configuring the databases for these services.

To create the SQL tracking database

  1. Using Microsoft SQL Server 2005 Express, SQL Server 2000 or later versions, or SQL Server 2000 Desktop Engine (MSDE), create a new database named Tracking by using the SQL query statement:

    CREATE DATABASE Tracking
    
  2. In the SQL Query Analyzer workspace, select the database that you created in step 1 in the list of available databases.

  3. On the File menu, click Open and open the SQL script %WINDIR%\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\<language>\Tracking_Schema.sql.

  4. Execute the query by clicking Execute or by pressing F5 to create the SQL Tracking Service tables.

  5. On the File menu, click Open and open the SQL script %WINDIR%\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\<language>\Tracking_Logic.sql.

  6. Execute the query by clicking Execute or by pressing F5 to create the SQL Tracking Service stored procedures.

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 <Solution file name>.

To run the sample

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

See Also

Footer image
Send comments about this topic to Microsoft.
Show:
© 2014 Microsoft