Barrier Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Enables multiple tasks to cooperatively work on an algorithm in parallel through multiple phases.

Inheritance Hierarchy

System..::.Object
System.Threading..::.Barrier

Namespace: System.Threading
Assembly: System (in System.dll)

Syntax

Public Class Barrier _
    Implements IDisposable
public class Barrier : IDisposable

The Barrier type exposes the following members.

Constructors

Name Description
Barrier(Int32) Initializes a new instance of the Barrier class.
Barrier(Int32, Action<(Of <(Barrier>)>)) Initializes a new instance of the Barrier class.

Top

Properties

Name Description
CurrentPhaseNumber Gets the number of the barrier's current phase.
ParticipantCount Gets the total number of participants in the barrier.
ParticipantsRemaining Gets the number of participants in the barrier that haven’t yet signaled in the current phase.

Top

Methods

Name Description
AddParticipant Notifies the Barrier that there will be an additional participant.
AddParticipants Notifies the Barrier that there will be additional participants.
Dispose()()() Releases all resources used by the current instance of the Barrier class.
Dispose(Boolean) Releases the unmanaged resources used by the Barrier, and optionally releases the managed resources.
Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
GetType Gets the Type of the current instance. (Inherited from Object.)
MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
RemoveParticipant Notifies the Barrier that there will be one less participant.
RemoveParticipants Notifies the Barrier that there will be fewer participants.
SignalAndWait()()() Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well.
SignalAndWait(CancellationToken) Signals that a participant has reached the barrier and waits for all other participants to reach the barrier, while observing a cancellation token.
SignalAndWait(Int32) Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a 32-bit signed integer to measure the timeout.
SignalAndWait(TimeSpan) Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a TimeSpan object to measure the time interval.
SignalAndWait(Int32, CancellationToken) Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a 32-bit signed integer to measure the timeout, while observing a cancellation token.
SignalAndWait(TimeSpan, CancellationToken) Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well, using a TimeSpan object to measure the time interval, while observing a cancellation token.
ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

A group of tasks cooperate by moving through a series of phases, where each in the group signals it has arrived at the Barrier in a given phase and implicitly waits for all others to arrive. The same Barrier can be used for multiple phases.

Examples

The following example shows how to use a barrier:

Version Information

Windows Phone OS

Supported in: 8.1, 8.0

Thread Safety

All public and protected members of Barrier are thread-safe and may be used concurrently from multiple threads, with the exception of Dispose, which must only be used when all other operations on the Barrier have completed.

See Also

Reference

System.Threading Namespace