Share via


WorkflowQueue.Count 屬性

定義

取得 WorkflowQueue 中所含的項目數。

public:
 property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer

屬性值

工作流程佇列中的項目數。

範例

下列程式碼範例將示範如何呼叫 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

適用於

另請參閱