WorkflowEventArgs 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
警告
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
- 繼承
- 衍生
- 屬性
範例
下列程式碼範例將示範呼叫事件處理常式方法時,如何使用 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 類別中提供所有工作流程事件的資料。 WorkflowEventArgs 是 WorkflowCompletedEventArgs、WorkflowSuspendedEventArgs 和 WorkflowTerminatedEventArgs 的基底類別。
屬性
WorkflowInstance |
已淘汰.
取得與工作流程事件關聯的工作流程執行個體。 |
方法
Equals(Object) |
已淘汰.
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
已淘汰.
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
已淘汰.
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
已淘汰.
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
已淘汰.
傳回代表目前物件的字串。 (繼承來源 Object) |