Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions xml/System.Collections.Concurrent/BlockingCollection`1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,31 @@
<format type="text/markdown"><![CDATA[

## Remarks
<xref:System.Collections.Concurrent.BlockingCollection`1> is a thread-safe collection class that provides the following:

- An implementation of the producer/consumer pattern; <xref:System.Collections.Concurrent.BlockingCollection`1> is a wrapper for the <xref:System.Collections.Concurrent.IProducerConsumerCollection`1> interface.
<xref:System.Collections.Concurrent.BlockingCollection`1> is a thread-safe collection class that provides the following:

- An implementation of the producer/consumer pattern; <xref:System.Collections.Concurrent.BlockingCollection`1> is a wrapper for the <xref:System.Collections.Concurrent.IProducerConsumerCollection`1> interface.
- Concurrent addition and removal of items from multiple threads with the <xref:System.Collections.Concurrent.BlockingCollection`1.Add*> and <xref:System.Collections.Concurrent.BlockingCollection`1.Take*> methods.

- A bounded collection that blocks <xref:System.Collections.Concurrent.BlockingCollection`1.Add*> and <xref:System.Collections.Concurrent.BlockingCollection`1.Take*> operations when the collection is full or empty.

- Cancellation of <xref:System.Collections.Concurrent.BlockingCollection`1.Add*> or <xref:System.Collections.Concurrent.BlockingCollection`1.Take*> operations by using a <xref:System.Threading.CancellationToken> object in the <xref:System.Collections.Concurrent.BlockingCollection`1.TryAdd*> or <xref:System.Collections.Concurrent.BlockingCollection`1.TryTake*> method.

> [!IMPORTANT]
> This type implements the <xref:System.IDisposable> interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its <xref:System.IDisposable.Dispose*> method in a `try`/`catch` block. To dispose of it indirectly, use a language construct such as `using` (in C#) or `Using` (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the <xref:System.IDisposable> interface topic. Also, note that the <xref:System.Collections.Concurrent.BlockingCollection`1.Dispose> method is not thread-safe. All other public and protected members of <xref:System.Collections.Concurrent.BlockingCollection`1> are thread-safe and may be used concurrently from multiple threads.
>
> - This type implements the <xref:System.IDisposable> interface. When you've finished using the type, you should dispose of it either directly (by calling its `Dispose` method) or indirectly (with a language construct such as `using` in C#). For more information, see [Use an object that implements IDisposable](xref:System.IDisposable#use-an-object-that-implements-idisposable).
> - The <xref:System.Collections.Concurrent.BlockingCollection`1.Dispose> method is not thread-safe. All other public and protected members of <xref:System.Collections.Concurrent.BlockingCollection`1> are thread-safe and can be used concurrently from multiple threads.

<xref:System.Collections.Concurrent.IProducerConsumerCollection`1> represents a collection that allows for thread-safe adding and removal of data. <xref:System.Collections.Concurrent.BlockingCollection`1> is used as a wrapper for an <xref:System.Collections.Concurrent.IProducerConsumerCollection`1> instance, and allows removal attempts from the collection to block until data is available to be removed. Similarly, you can create a <xref:System.Collections.Concurrent.BlockingCollection`1> to enforce an upper bound on the number of data elements allowed in the <xref:System.Collections.Concurrent.IProducerConsumerCollection`1>; addition attempts to the collection may then block until space is available to store the added items. In this manner, <xref:System.Collections.Concurrent.BlockingCollection`1> is similar to a traditional blocking queue data structure, except that the underlying data storage mechanism is abstracted away as an <xref:System.Collections.Concurrent.IProducerConsumerCollection`1>.
<xref:System.Collections.Concurrent.IProducerConsumerCollection`1> represents a collection that allows for thread-safe adding and removal of data. <xref:System.Collections.Concurrent.BlockingCollection`1> is used as a wrapper for an <xref:System.Collections.Concurrent.IProducerConsumerCollection`1> instance, and allows removal attempts from the collection to block until data is available to be removed. Similarly, you can create a <xref:System.Collections.Concurrent.BlockingCollection`1> to enforce an upper bound on the number of data elements allowed in the <xref:System.Collections.Concurrent.IProducerConsumerCollection`1>; addition attempts to the collection may then block until space is available to store the added items. In this manner, <xref:System.Collections.Concurrent.BlockingCollection`1> is similar to a traditional blocking queue data structure, except that the underlying data storage mechanism is abstracted away as an <xref:System.Collections.Concurrent.IProducerConsumerCollection`1>.

<xref:System.Collections.Concurrent.BlockingCollection`1> supports bounding and blocking. Bounding means that you can set the maximum capacity of the collection. Bounding is important in certain scenarios because it enables you to control the maximum size of the collection in memory, and it prevents the producing threads from moving too far ahead of the consuming threads.Multiple threads or tasks can add items to the collection concurrently, and if the collection reaches its specified maximum capacity, the producing threads will block until an item is removed. Multiple consumers can remove items concurrently, and if the collection becomes empty, the consuming threads will block until a producer adds an item. A producing thread can call the <xref:System.Collections.Concurrent.BlockingCollection`1.CompleteAdding*> method to indicate that no more items will be added. Consumers monitor the <xref:System.Collections.Concurrent.BlockingCollection`1.IsCompleted> property to know when the collection is empty and no more items will be added.
<xref:System.Collections.Concurrent.BlockingCollection`1> supports bounding and blocking. Bounding means that you can set the maximum capacity of the collection. Bounding is important in certain scenarios because it enables you to control the maximum size of the collection in memory, and it prevents the producing threads from moving too far ahead of the consuming threads.Multiple threads or tasks can add items to the collection concurrently, and if the collection reaches its specified maximum capacity, the producing threads will block until an item is removed. Multiple consumers can remove items concurrently, and if the collection becomes empty, the consuming threads will block until a producer adds an item. A producing thread can call the <xref:System.Collections.Concurrent.BlockingCollection`1.CompleteAdding*> method to indicate that no more items will be added. Consumers monitor the <xref:System.Collections.Concurrent.BlockingCollection`1.IsCompleted> property to know when the collection is empty and no more items will be added.
Comment thread
gewarren marked this conversation as resolved.
Outdated

<xref:System.Collections.Concurrent.BlockingCollection`1.Add*> and <xref:System.Collections.Concurrent.BlockingCollection`1.Take*> operations are typically performed in a loop. You can cancel a loop by passing in a <xref:System.Threading.CancellationToken> object to the <xref:System.Collections.Concurrent.BlockingCollection`1.TryAdd*> or <xref:System.Collections.Concurrent.BlockingCollection`1.TryTake*> method, and then checking the value of the token's <xref:System.Threading.CancellationToken.IsCancellationRequested> property on each iteration. If the value is `true`, it is up to you to respond the cancellation request by cleaning up any resources and exiting the loop.
<xref:System.Collections.Concurrent.BlockingCollection`1.Add*> and <xref:System.Collections.Concurrent.BlockingCollection`1.Take*> operations are typically performed in a loop. You can cancel a loop by passing in a <xref:System.Threading.CancellationToken> object to the <xref:System.Collections.Concurrent.BlockingCollection`1.TryAdd*> or <xref:System.Collections.Concurrent.BlockingCollection`1.TryTake*> method, and then checking the value of the token's <xref:System.Threading.CancellationToken.IsCancellationRequested> property on each iteration. If the value is `true`, it is up to you to respond the cancellation request by cleaning up any resources and exiting the loop.

When you create a <xref:System.Collections.Concurrent.BlockingCollection`1> object, you can specify not only the bounded capacity but also the type of collection to use. For example, you could specify a <xref:System.Collections.Concurrent.ConcurrentQueue`1> object for first in, first out (FIFO) behavior, or a <xref:System.Collections.Concurrent.ConcurrentStack`1> object for last in, first out (LIFO) behavior. You can use any collection class that implements the <xref:System.Collections.Concurrent.IProducerConsumerCollection`1> interface. The default collection type for <xref:System.Collections.Concurrent.BlockingCollection`1> is <xref:System.Collections.Concurrent.ConcurrentQueue`1>.
When you create a <xref:System.Collections.Concurrent.BlockingCollection`1> object, you can specify not only the bounded capacity but also the type of collection to use. For example, you could specify a <xref:System.Collections.Concurrent.ConcurrentQueue`1> object for first in, first out (FIFO) behavior, or a <xref:System.Collections.Concurrent.ConcurrentStack`1> object for last in, first out (LIFO) behavior. You can use any collection class that implements the <xref:System.Collections.Concurrent.IProducerConsumerCollection`1> interface. The default collection type for <xref:System.Collections.Concurrent.BlockingCollection`1> is <xref:System.Collections.Concurrent.ConcurrentQueue`1>.

Do not modify the underlying collection directly. Use <xref:System.Collections.Concurrent.BlockingCollection`1> methods to add or remove elements. The <xref:System.Collections.Concurrent.BlockingCollection`1> object can become corrupted if you change the underlying collection directly.
Do not modify the underlying collection directly. Use <xref:System.Collections.Concurrent.BlockingCollection`1> methods to add or remove elements. The <xref:System.Collections.Concurrent.BlockingCollection`1> object can become corrupted if you change the underlying collection directly.

<xref:System.Collections.Concurrent.BlockingCollection`1> was not designed with asynchronous access in mind. If your application requires asynchronous producer/consumer scenarios, consider using <xref:System.Threading.Channels.Channel`1> instead.



## Examples
The following example shows how to add and take items concurrently from a blocking collection:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
## Remarks
> [!IMPORTANT]
> This type implements the <xref:System.IDisposable> interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its <xref:System.IDisposable.Dispose*> method in a `try`/`catch` block. To dispose of it indirectly, use a language construct such as `using` (in C#) or `Using` (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the <xref:System.IDisposable> interface topic.
> This type implements the <xref:System.IDisposable> interface. When you've finished using the type, you should dispose of it either directly (by calling its `Dispose` method) or indirectly (with a language construct such as `using` in C#). For more information, see [Use an object that implements IDisposable](xref:System.IDisposable#use-an-object-that-implements-idisposable).
]]></format>
</remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
## Remarks
> [!IMPORTANT]
> This type implements the <xref:System.IDisposable> interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its <xref:System.IDisposable.Dispose*> method in a `try`/`catch` block. To dispose of it indirectly, use a language construct such as `using` (in C#) or `Using` (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the <xref:System.IDisposable> interface topic.
> This type implements the <xref:System.IDisposable> interface. When you've finished using the type, you should dispose of it either directly (by calling its `Dispose` method) or indirectly (with a language construct such as `using` in C#). For more information, see [Use an object that implements IDisposable](xref:System.IDisposable#use-an-object-that-implements-idisposable).
]]></format>
</remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
## Remarks

> [!IMPORTANT]
> This type implements the <xref:System.IDisposable> interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its <xref:System.IDisposable.Dispose*> method in a `try`/`catch` block. To dispose of it indirectly, use a language construct such as `using` (in C#) or `Using` (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the <xref:System.IDisposable> interface topic.
> This type implements the <xref:System.IDisposable> interface. When you've finished using the type, you should dispose of it either directly (by calling its `Dispose` method) or indirectly (with a language construct such as `using` in C#). For more information, see [Use an object that implements IDisposable](xref:System.IDisposable#use-an-object-that-implements-idisposable).

]]></format>
</remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
An <xref:System.ComponentModel.Composition.Hosting.AssemblyCatalog> is used to parse all the parts present in a specified assembly. The target assembly can be indicated either by object reference or by path.

> [!IMPORTANT]
> This type implements the <xref:System.IDisposable> interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its <xref:System.IDisposable.Dispose*> method in a `try`/`catch` block. To dispose of it indirectly, use a language construct such as `using` (in C#) or `Using` (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the <xref:System.IDisposable> interface topic.
> This type implements the <xref:System.IDisposable> interface. When you've finished using the type, you should dispose of it either directly (by calling its `Dispose` method) or indirectly (with a language construct such as `using` in C#). For more information, see [Use an object that implements IDisposable](xref:System.IDisposable#use-an-object-that-implements-idisposable).

This type is thread safe.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
## Remarks
> [!IMPORTANT]
> This type implements the <xref:System.IDisposable> interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its <xref:System.IDisposable.Dispose*> method in a `try`/`catch` block. To dispose of it indirectly, use a language construct such as `using` (in C#) or `Using` (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the <xref:System.IDisposable> interface topic.
> This type implements the <xref:System.IDisposable> interface. When you've finished using the type, you should dispose of it either directly (by calling its `Dispose` method) or indirectly (with a language construct such as `using` in C#). For more information, see [Use an object that implements IDisposable](xref:System.IDisposable#use-an-object-that-implements-idisposable).
]]></format>
</remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
## Remarks

> [!IMPORTANT]
> This type implements the <xref:System.IDisposable> interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its <xref:System.IDisposable.Dispose*> method in a `try`/`catch` block. To dispose of it indirectly, use a language construct such as `using` (in C#) or `Using` (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the <xref:System.IDisposable> interface topic.
> This type implements the <xref:System.IDisposable> interface. When you've finished using the type, you should dispose of it either directly (by calling its `Dispose` method) or indirectly (with a language construct such as `using` in C#). For more information, see [Use an object that implements IDisposable](xref:System.IDisposable#use-an-object-that-implements-idisposable).

]]></format>
</remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
## Remarks

> [!IMPORTANT]
> This type implements the <xref:System.IDisposable> interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its <xref:System.IDisposable.Dispose*> method in a `try`/`catch` block. To dispose of it indirectly, use a language construct such as `using` (in C#) or `Using` (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the <xref:System.IDisposable> interface topic.
> This type implements the <xref:System.IDisposable> interface. When you've finished using the type, you should dispose of it either directly (by calling its `Dispose` method) or indirectly (with a language construct such as `using` in C#). For more information, see [Use an object that implements IDisposable](xref:System.IDisposable#use-an-object-that-implements-idisposable).

]]></format>
</remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
A <xref:System.ComponentModel.Composition.Hosting.CompositionContainer> object serves two major purposes in an application. First, it keeps track of which parts are available for composition and what their dependencies are, and performs composition whenever the set of available parts changes. Second, it provides the methods by which the application gets instances of composed parts or fills the dependencies of a composable part.

> [!IMPORTANT]
> This type implements the <xref:System.IDisposable> interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its <xref:System.IDisposable.Dispose*> method in a `try`/`catch` block. To dispose of it indirectly, use a language construct such as `using` (in C#) or `Using` (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the <xref:System.IDisposable> interface topic.
> This type implements the <xref:System.IDisposable> interface. When you've finished using the type, you should dispose of it either directly (by calling its `Dispose` method) or indirectly (with a language construct such as `using` in C#). For more information, see [Use an object that implements IDisposable](xref:System.IDisposable#use-an-object-that-implements-idisposable).

Parts can be made available to the container either directly or through the <xref:System.ComponentModel.Composition.Hosting.CompositionContainer.Catalog> property. All the parts discoverable in this <xref:System.ComponentModel.Composition.Primitives.ComposablePartCatalog> are available to the container to fulfill imports, along with any parts added directly.

Expand Down
Loading
Loading