WorkflowQueue.Dequeue Metoda

Definicja

Usuwa i zwraca obiekt na początku obiektu WorkflowQueue.

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

Zwraca

Obiekt, który jest usuwany od początku obiektu WorkflowQueue.

Wyjątki

Wartość jest pusta WorkflowQueue .

Przykłady

W poniższym przykładzie kodu pokazano, jak można utworzyć klasę WorkflowQueue , wywołując metodę WorkflowQueuingService.GetWorkflowQueue . Używa również właściwości , Count aby określić, czy jakiekolwiek komunikaty istnieją w bieżącej kolejce. Na koniec kod używa Dequeue metody , aby usunąć i zwrócić pierwszy obiekt w kolejce.

Ten przykład kodu jest częścią przykładu zestawu SDK działania obserwatora plików z pliku FileSystemEvent.cs. Aby uzyskać więcej informacji, zobacz Działanie obserwatora systemu plików.

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

Uwagi

Możesz sprawdzić Count , czy wartość WorkflowQueue jest pusta przed wywołaniem Dequeuemetody , czy można przechwycić InvalidOperationExceptionelement .

Dotyczy

Zobacz też