This documentation is archived and is not being maintained.

WorkflowEventArgs Class

Provides data for workflow events.

Namespace:  System.Workflow.Runtime
Assembly:  System.Workflow.Runtime (in System.Workflow.Runtime.dll)

public class WorkflowEventArgs : EventArgs

Workflow events are associated with a workflow instance. A WorkflowEventArgs contains the WorkflowInstance associated with the workflow event. A WorkflowEventArgs or an object that derives from the WorkflowEventArgs class provides the data for all of the workflow events in the WorkflowRuntime class. WorkflowEventArgs is the base class for WorkflowCompletedEventArgs, WorkflowSuspendedEventArgs, and WorkflowTerminatedEventArgs.

The following code example demonstrates how to obtain a WorkflowInstance object using the WorkflowInstance property when an event handler method is called. When the WorkflowIdled event occurs, the OnWorkflowIdled method defined in this example is called. It determines which workflow is idled using the WorkflowInstance property and then gets a collection of queued items for the workflow instance by calling the GetWorkflowQueueData method. The code iterates over the collection to determine which activity is waiting for the event that idled the workflow. It then sends an exception to the workflow queue using the EnqueueItem method along with the name of the event queue item.

This code example is part of the Canceling a Workflow SDK Sample from the Program.cs file. For more information, see Canceling a Workflow.

static void OnWorkflowIdled(object sender, WorkflowEventArgs e)
    WorkflowInstance workflow = e.WorkflowInstance;

    Console.WriteLine("\n...waiting for 3 seconds... \n");

    // what activity is blocking the workflow
    ReadOnlyCollection<WorkflowQueueInfo> wqi = workflow.GetWorkflowQueueData();
    foreach (WorkflowQueueInfo q in wqi)
        EventQueueName eq = q.QueueName as EventQueueName;
        if (eq != null)
            // get activity that is waiting for event
            ReadOnlyCollection<string> blockedActivity = q.SubscribedActivityNames;
            Console.WriteLine("Host: Workflow is blocked on " + blockedActivity[0]);

            // this event is never going to arrive eg. employee left the company 
            // lets send an exception to this queue 
            // it will either be handled by exception handler that was modeled in workflow 
            // or the runtime will unwind running compensation handlers and exit the workflow
            Console.WriteLine("Host: This event is not going to arrive");
            Console.WriteLine("Host: Cancel workflow with unhandled exception");
            workflow.EnqueueItem(q.QueueName, new Exception("ExitWorkflowException"), null, null);

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0