WorkflowInstance.GetWorkflowQueueData 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取 WorkflowQueueInfo 对象的集合,该集合包含与此工作流实例关联的工作流队列的挂起项和订阅活动。
public:
System::Collections::ObjectModel::ReadOnlyCollection<System::Workflow::Runtime::WorkflowQueueInfo ^> ^ GetWorkflowQueueData();
public System.Collections.ObjectModel.ReadOnlyCollection<System.Workflow.Runtime.WorkflowQueueInfo> GetWorkflowQueueData ();
member this.GetWorkflowQueueData : unit -> System.Collections.ObjectModel.ReadOnlyCollection<System.Workflow.Runtime.WorkflowQueueInfo>
Public Function GetWorkflowQueueData () As ReadOnlyCollection(Of WorkflowQueueInfo)
返回
一个由 ReadOnlyCollection<T> 对象构成的 WorkflowQueueInfo。
例外
工作流运行时引擎未运行。
示例
下面的代码示例演示如何使用 GetWorkflowQueueData 方法获取有关与 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
注解
GetWorkflowQueueData 将返回 WorkflowQueueInfo 对象的集合,每个集合都包含与此工作流实例关联的其中一个工作流队列状态的有关信息。 WorkflowQueueInfo.Items 包含 WorkflowQueue 的挂起项,WorkflowQueueInfo.SubscribedActivityNames 包含一个活动列表,需要订阅这些活动以便在 WorkflowQueue 上发送项。