本文整理汇总了C#中AsyncQueue.TryDequeue方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncQueue.TryDequeue方法的具体用法?C# AsyncQueue.TryDequeue怎么用?C# AsyncQueue.TryDequeue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncQueue
的用法示例。
在下文中一共展示了AsyncQueue.TryDequeue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Count_nonempty
public void Count_nonempty()
{
var queue = new AsyncQueue<string>();
queue.Enqueue("A");
queue.Enqueue("B");
queue.Enqueue("C");
queue.Enqueue("D");
Assert.IsTrue(queue.TryDequeue());
Assert.AreEqual(3, queue.Count);
}
示例2: DequeueCompilationEvents
private static bool DequeueCompilationEvents(AsyncQueue<CompilationEvent> eventQueue, out bool compilationStartedFired, out HashSet<string> declaredSymbolNames, out HashSet<string> completedCompilationUnits)
{
compilationStartedFired = false;
declaredSymbolNames = new HashSet<string>();
completedCompilationUnits = new HashSet<string>();
if (eventQueue.Count == 0)
{
return false;
}
CompilationEvent compEvent;
while (eventQueue.TryDequeue(out compEvent))
{
if (compEvent is CompilationStartedEvent)
{
Assert.False(compilationStartedFired, "Unexpected multiple compilation stated events");
compilationStartedFired = true;
}
else
{
var symbolDeclaredEvent = compEvent as SymbolDeclaredCompilationEvent;
if (symbolDeclaredEvent != null)
{
var added = declaredSymbolNames.Add(symbolDeclaredEvent.Symbol.Name);
Assert.True(added, "Unexpected multiple symbol declared events for symbol " + symbolDeclaredEvent.Symbol);
}
else
{
var compilationCompeletedEvent = compEvent as CompilationUnitCompletedEvent;
if (compilationCompeletedEvent != null)
{
Assert.True(completedCompilationUnits.Add(compilationCompeletedEvent.CompilationUnit.FilePath));
}
}
}
}
return true;
}
示例3: FreeEventQueue
private void FreeEventQueue(AsyncQueue<CompilationEvent> eventQueue)
{
if (eventQueue == null || ReferenceEquals(eventQueue, s_EmptyEventQueue))
{
return;
}
Debug.Assert(!eventQueue.IsCompleted);
if (eventQueue.Count > 0)
{
CompilationEvent discarded;
while (eventQueue.TryDequeue(out discarded)) ;
}
s_eventQueuePool.Free(eventQueue);
}
示例4: FreeEventQueue
private static void FreeEventQueue(AsyncQueue<CompilationEvent> eventQueue, ObjectPool<AsyncQueue<CompilationEvent>> eventQueuePool)
{
if (eventQueue == null || ReferenceEquals(eventQueue, s_EmptyEventQueue))
{
return;
}
if (eventQueue.Count > 0)
{
CompilationEvent discarded;
while (eventQueue.TryDequeue(out discarded)) ;
}
if (!eventQueue.IsCompleted)
{
eventQueuePool.Free(eventQueue);
}
else
{
eventQueuePool.ForgetTrackedObject(eventQueue);
}
}
示例5: TryDequeueAfterComplete
public async Task TryDequeueAfterComplete()
{
var queue = new AsyncQueue<int>();
queue.Enqueue(13);
queue.Complete();
await queue.WhenCompletedTask.ConfigureAwait(false);
int value;
Assert.True(queue.TryDequeue(out value));
Assert.Equal(13, value);
}
示例6: TryDequeue
public void TryDequeue()
{
var queue = new AsyncQueue<int>();
int value;
Assert.False(queue.TryDequeue(out value));
queue.Enqueue(13);
Assert.True(queue.TryDequeue(out value));
Assert.Equal(13, value);
}
示例7: TryDequeue_nonempty
public void TryDequeue_nonempty()
{
var queue = new AsyncQueue<string>();
queue.Enqueue("A");
string value;
Assert.IsTrue(queue.TryDequeue(out value));
Assert.AreEqual("A", value);
Assert.AreEqual(0, queue.Count);
}
示例8: TryDequeue_empty
public void TryDequeue_empty()
{
var queue = new AsyncQueue<string>();
Assert.IsFalse(queue.TryDequeue());
}