generic <typename T>
public ref class ConcurrentQueue : System::Collections::Concurrent::IProducerConsumerCollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::ICollection
generic <typename T>
public ref class ConcurrentQueue : System::Collections::Concurrent::IProducerConsumerCollection<T>, System::Collections::Generic::IEnumerable<T>
generic <typename T>
public ref class ConcurrentQueue : System::Collections::Concurrent::IProducerConsumerCollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IReadOnlyCollection<T>
generic <typename T>
public ref class ConcurrentQueue : System::Collections::Concurrent::IProducerConsumerCollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::ICollection
public class ConcurrentQueue<T> : System.Collections.Concurrent.IProducerConsumerCollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.ICollection
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class ConcurrentQueue<T> : System.Collections.Concurrent.IProducerConsumerCollection<T>, System.Collections.Generic.IEnumerable<T>
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class ConcurrentQueue<T> : System.Collections.Concurrent.IProducerConsumerCollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>
public class ConcurrentQueue<T> : System.Collections.Concurrent.IProducerConsumerCollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.ICollection
public class ConcurrentQueue<T> : System.Collections.Concurrent.IProducerConsumerCollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>
type ConcurrentQueue<'T> = class
interface IProducerConsumerCollection<'T>
interface seq<'T>
interface IEnumerable
interface ICollection
interface IReadOnlyCollection<'T>
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type ConcurrentQueue<'T> = class
interface IProducerConsumerCollection<'T>
interface seq<'T>
interface ICollection
interface IEnumerable
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type ConcurrentQueue<'T> = class
interface IProducerConsumerCollection<'T>
interface seq<'T>
interface IEnumerable
interface ICollection
interface IReadOnlyCollection<'T>
type ConcurrentQueue<'T> = class
interface IProducerConsumerCollection<'T>
interface seq<'T>
interface ICollection
interface IEnumerable
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type ConcurrentQueue<'T> = class
interface IProducerConsumerCollection<'T>
interface IReadOnlyCollection<'T>
interface seq<'T>
interface ICollection
interface IEnumerable
Public Class ConcurrentQueue(Of T)
Implements ICollection, IEnumerable(Of T), IProducerConsumerCollection(Of T), IReadOnlyCollection(Of T)
Public Class ConcurrentQueue(Of T)
Implements IEnumerable(Of T), IProducerConsumerCollection(Of T)
Public Class ConcurrentQueue(Of T)
Implements IEnumerable(Of T), IProducerConsumerCollection(Of T), IReadOnlyCollection(Of T)
Public Class ConcurrentQueue(Of T)
Implements ICollection, IEnumerable(Of T), IProducerConsumerCollection(Of T)
// ConcurrentQueue<T>.Enqueue()
// ConcurrentQueue<T>.TryPeek()
// ConcurrentQueue<T>.TryDequeue()
static void Main ()
// Construct a ConcurrentQueue.
ConcurrentQueue<int> cq = new ConcurrentQueue<int>();
// Populate the queue.
for (int i = 0; i < 10000; i++)
cq.Enqueue(i);
// Peek at the first element.
int result;
if (!cq.TryPeek(out result))
Console.WriteLine("CQ: TryPeek failed when it should have succeeded");
else if (result != 0)
Console.WriteLine("CQ: Expected TryPeek result of 0, got {0}", result);
int outerSum = 0;
// An action to consume the ConcurrentQueue.
Action action = () =>
int localSum = 0;
int localValue;
while (cq.TryDequeue(out localValue)) localSum += localValue;
Interlocked.Add(ref outerSum, localSum);
// Start 4 concurrent consuming actions.
Parallel.Invoke(action, action, action, action);
Console.WriteLine("outerSum = {0}, should be 49995000", outerSum);
open System
open System.Collections.Concurrent
open System.Threading
open System.Threading.Tasks
// Demonstrates:
// ConcurrentQueue<T>.Enqueue()
// ConcurrentQueue<T>.TryPeek()
// ConcurrentQueue<T>.TryDequeue()
// Construct a ConcurrentQueue.
let cq = ConcurrentQueue<int>()
// Populate the queue.
for i = 0 to 9999 do
cq.Enqueue i
// Peek at the first element.
let mutable result = 0
if cq.TryPeek &result |> not then
printfn "CQ: TryPeek failed when it should have succeeded"
elif result <> 0 then
printfn $"CQ: Expected TryPeek result of 0, got {result}"
let mutable outerSum = 0
// An action to consume the ConcurrentQueue.
let action =
Action(fun () ->
let mutable localSum = 0
let mutable localValue = 0
while cq.TryDequeue &localValue do
localSum <- localSum + localValue
Interlocked.Add(&outerSum, localSum) |> ignore)
// Start 4 concurrent consuming actions.
Parallel.Invoke(action, action, action, action)
printfn $"outerSum = {outerSum}, should be 49995000"
Imports System.Collections.Concurrent
Imports System.Threading
Imports System.Threading.Tasks
Class TestQueue
' Demonstrates:
' ConcurrentQueue<T>.Enqueue()
' ConcurrentQueue<T>.TryPeek()
' ConcurrentQueue<T>.TryDequeue()
Shared Sub Main()
' Construct a ConcurrentQueue
Dim cq As New ConcurrentQueue(Of Integer)()
' Populate the queue
For i As Integer = 0 To 9999
cq.Enqueue(i)
' Peek at the first element
Dim result As Integer
If Not cq.TryPeek(result) Then
Console.WriteLine("CQ: TryPeek failed when it should have succeeded")
ElseIf result <> 0 Then
Console.WriteLine("CQ: Expected TryPeek result of 0, got {0}", result)
End If
Dim outerSum As Integer = 0
' An action to consume the ConcurrentQueue
Dim action As Action =
Sub()
Dim localSum As Integer = 0
Dim localValue As Integer
While cq.TryDequeue(localValue)
localSum += localValue
End While
Interlocked.Add(outerSum, localSum)
End Sub
' Start 4 concurrent consuming actions
Parallel.Invoke(action, action, action, action)
Console.WriteLine("outerSum = {0}, should be 49995000", outerSum)
End Sub
End Class
ConcurrentQueue<T>
會
IReadOnlyCollection<T>
實作從 .NET Framework 4.6 開始的介面;在舊版的 .NET Framework 中,類別
ConcurrentQueue<T>
並未實作此介面。
ToImmutableDictionary<TSource,TKey,TValue>(IEnumerable<TSource>,
Func<TSource,TKey>, Func<TSource,TValue>, IEqualityComparer<TKey>,
IEqualityComparer<TValue>)
列舉及轉換序列,並使用指定的索引鍵與值比較子產生其內容的不可變字典。
GroupBy<TSource,TKey,TElement,TResult>(IEnumerable<TSource>, Func<TSource,
TKey>, Func<TSource,TElement>, Func<TKey,IEnumerable<TElement>,
TResult>, IEqualityComparer<TKey>)
依據指定的索引鍵選取器函式來群組序列的項目,並從每個群組及其索引鍵建立結果值。 索引鍵值是使用指定的比較子來進行比較,而每個群組的項目則都是利用指定的函式進行投影。
GroupJoin<TOuter,TInner,TKey,TResult>(IEnumerable<TOuter>, IEnumerable<TInner>,
Func<TOuter,TKey>, Func<TInner,TKey>, Func<TOuter,IEnumerable<TInner>,
TResult>)
根據索引鍵相等與否,將兩個序列的項目相互關聯,並群組產生的結果。 預設的相等比較子是用於比較索引鍵。
GroupJoin<TOuter,TInner,TKey,TResult>(IEnumerable<TOuter>, IEnumerable<TInner>,
Func<TOuter,TKey>, Func<TInner,TKey>, Func<TOuter,IEnumerable<TInner>,
TResult>, IEqualityComparer<TKey>)
根據索引鍵相等與否,將兩個序列的項目相互關聯,並群組產生的結果。 指定的
IEqualityComparer<T>
是用於比較索引鍵。
Join<TOuter,TInner,TKey,TResult>(IEnumerable<TOuter>, IEnumerable<TInner>,
Func<TOuter,TKey>, Func<TInner,TKey>, Func<TOuter,TInner,TResult>,
IEqualityComparer<TKey>)
根據相符索引鍵,將兩個序列的項目相互關聯。 指定的
IEqualityComparer<T>
是用於比較索引鍵。