Share via


WorkflowQueue.Dequeue Metodo

Definizione

Consente di rimuovere e restituire l'oggetto all'inizio della WorkflowQueue.

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

Restituisce

Oggetto rimosso dall'inizio della WorkflowQueue .

Eccezioni

Esempio

Nell'esempio di codice seguente viene illustrato come creare una classe WorkflowQueue chiamando il metodo WorkflowQueuingService.GetWorkflowQueue. Viene inoltre utilizzata la proprietà Count per determinare se siano presenti messaggi nella coda corrente. Infine, il codice utilizza il metodo Dequeue per rimuovere e restituire il primo oggetto contenuto nella coda.

Questo esempio di codice fa parte dell'esempio SDK File Watcher Activity nel file FileSystemEvent.cs. Per altre informazioni, vedere Attività Watcher di File System.

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

Commenti

È possibile controllare Count per determinare se WorkflowQueue è vuota prima di chiamare Dequeue oppure è possibile intercettare InvalidOperationException.

Si applica a

Vedi anche