Share via


WorkflowQueue.Dequeue 方法

定義

移除並傳回在 WorkflowQueue 開頭的物件。

public:
 System::Object ^ Dequeue();
public object Dequeue ();
member this.Dequeue : unit -> obj
Public Function Dequeue () As Object

傳回

WorkflowQueue 的開頭移除的物件。

例外狀況

範例

下列程式碼範例將示範如何呼叫 WorkflowQueue 方法來建立 WorkflowQueuingService.GetWorkflowQueue。 它也會使用 Count 屬性來判斷目前的佇列中是否有任何訊息。 最後,此程式碼會使用 Dequeue 方法來移除並傳回佇列中的第一個物件。

這個程式碼範例是 FileSystemEvent.cs 檔案中<檔案監看員活動 SDK>範例的一部分。 如需詳細資訊,請參閱 檔案系統監看員活動

private bool ProcessQueueItem(ActivityExecutionContext context)
{
    WorkflowQueuingService qService = context.GetService<WorkflowQueuingService>();
    if (!qService.Exists(this.QueueName))
    {
        return false;
    }

    WorkflowQueue queue = qService.GetWorkflowQueue(this.QueueName);

    // If the queue has messages, then process the first one
    if (queue.Count == 0)
    {
        return false;
    }

    FileWatcherEventArgs e = (FileWatcherEventArgs)queue.Dequeue();

    // Raise the FileSystemEvent
    base.RaiseGenericEvent<FileWatcherEventArgs>(FileSystemEvent.FileWatcherEventHandlerEvent, this, e);

    DoUnsubscribe(context, this);
    DeleteQueue(context);
    return true;
}
Private Function ProcessQueueItem(ByVal context As ActivityExecutionContext) As Boolean

    Dim qService As WorkflowQueuingService = context.GetService(Of WorkflowQueuingService)()

    If Not qService.Exists(Me.QueueName) Then
        Return False
    End If

    Dim Queue As WorkflowQueue = qService.GetWorkflowQueue(Me.QueueName)

    ' If the queue has messages, then process the first one
    If Queue.Count = 0 Then
        Return False
    End If

    Dim e As FileWatcherEventArgs = CType(Queue.Dequeue(), FileWatcherEventArgs)

    ' Raise the FileSystemEvent
    MyBase.RaiseGenericEvent(Of FileWatcherEventArgs)(FileSystemEvent.FileWatcherEventHandlerEvent, Me, e)
    DoUnsubscribe(context, Me)
    DeleteQueue(context)
    Return True
End Function

備註

在呼叫 Count 之前,您可以檢查 WorkflowQueue 以判斷 Dequeue 是否為空,否則可能會攔截到 InvalidOperationException

適用於

另請參閱