WorkflowEventArgs 类

定义

警告

此 API 现已过时。

提供有关工作流事件的数据。Provides data for workflow events.

public ref class WorkflowEventArgs : EventArgs
[System.Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
public class WorkflowEventArgs : EventArgs
type WorkflowEventArgs = class
    inherit EventArgs
Public Class WorkflowEventArgs
Inherits EventArgs
继承
WorkflowEventArgs
派生
属性

示例

下面的代码示例演示如何在调用事件处理程序方法时使用 WorkflowInstance 属性来获取 WorkflowInstance 对象。The following code example demonstrates how to obtain a WorkflowInstance object using the WorkflowInstance property when an event handler method is called. WorkflowIdled 事件发生时,调用本示例中定义的 OnWorkflowIdled 方法。When the WorkflowIdled event occurs, the OnWorkflowIdled method defined in this example is called. 该方法使用 WorkflowInstance 属性来确定哪个工作流处于空闲状态,然后通过调用 GetWorkflowQueueData 方法来获取该工作流实例的排队项的集合。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. 然后,该代码将使用 EnqueueItem 方法以及事件队列项的名称向工作流队列发出一个异常。It then sends an exception to the workflow queue using the EnqueueItem method along with the name of the event queue item.

此代码示例摘自 Program.cs 文件中的“取消工作流”SDK 示例。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");
    Thread.Sleep(3000);

    // 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);
        }
    }
}
Shared Sub OnWorkflowIdled(ByVal sender As Object, ByVal e As WorkflowEventArgs)
    Dim workflow As WorkflowInstance = e.WorkflowInstance

    Console.WriteLine(vbCrLf + "...waiting for 3 seconds... " + vbCrLf)
    Thread.Sleep(3000)

    ' what activity is blocking the workflow
    Dim wqi As ReadOnlyCollection(Of WorkflowQueueInfo) = workflow.GetWorkflowQueueData()
    For Each q As WorkflowQueueInfo In wqi

        Dim eq As EventQueueName = TryCast(q.QueueName, EventQueueName)

        If eq IsNot Nothing Then
            ' get activity that is waiting for event
            Dim blockedActivity As ReadOnlyCollection(Of String) = 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"), Nothing, Nothing)
        End If
    Next
End Sub

注解

备注

本材料讨论的类型和命名空间已废弃不用。This material discusses types and namespaces that are obsolete. 有关详细信息,请参阅 Windows Workflow Foundation 4.5 中弃用的类型For more information, see Deprecated Types in Windows Workflow Foundation 4.5.

与工作流实例关联的工作流事件。Workflow events are associated with a workflow instance. 一个 WorkflowEventArgs,包含与工作流事件关联的 WorkflowInstanceA WorkflowEventArgs contains the WorkflowInstance associated with the workflow event. WorkflowEventArgs 类派生的 WorkflowEventArgs 或对象可提供 WorkflowRuntime 类中所有工作流事件的有关数据。A WorkflowEventArgs or an object that derives from the WorkflowEventArgs class provides the data for all of the workflow events in the WorkflowRuntime class. WorkflowEventArgsWorkflowCompletedEventArgsWorkflowSuspendedEventArgsWorkflowTerminatedEventArgs 的基类。WorkflowEventArgs is the base class for WorkflowCompletedEventArgs, WorkflowSuspendedEventArgs, and WorkflowTerminatedEventArgs.

属性

WorkflowInstance

获取与工作流事件关联的工作流实例。Gets the workflow instance associated with the workflow event.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅