WorkflowEventArgs 类

定义

注意

The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*

提供有关工作流事件的数据。

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

示例

下面的代码示例演示如何在调用事件处理程序方法时使用 WorkflowInstance 属性来获取 WorkflowInstance 对象。 当 WorkflowIdled 事件发生时,调用本示例中定义的 OnWorkflowIdled 方法。 该方法使用 WorkflowInstance 属性来确定哪个工作流处于空闲状态,然后通过调用 GetWorkflowQueueData 方法来获取该工作流实例的排队项的集合。 该代码会循环访问该集合以确定哪个活动正在等待使工作流处于空闲状态的事件。 然后,该代码将使用 EnqueueItem 方法以及事件队列项的名称向工作流队列发出一个异常。

此代码示例摘自 Program.cs 文件中的“取消工作流”SDK 示例。 有关详细信息,请参阅 取消工作流

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

注解

注意

本材料讨论的类型和命名空间已废弃不用。 有关详细信息,请参阅 Windows Workflow Foundation 4.5 中弃用的类型

与工作流实例关联的工作流事件。 一个 WorkflowEventArgs,包含与工作流事件关联的 WorkflowInstance。 从 WorkflowEventArgs 类派生的 WorkflowEventArgs 或对象可提供 WorkflowRuntime 类中所有工作流事件的有关数据。 WorkflowEventArgsWorkflowCompletedEventArgsWorkflowSuspendedEventArgsWorkflowTerminatedEventArgs 的基类。

属性

WorkflowInstance
已过时.

获取与工作流事件关联的工作流实例。

方法

Equals(Object)
已过时.

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()
已过时.

作为默认哈希函数。

(继承自 Object)
GetType()
已过时.

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()
已过时.

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()
已过时.

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅