Barrier Class

July 28, 2014

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

System.Object
  System.Threading.Barrier

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

public class Barrier : IDisposable

The Barrier type exposes the following members.

  NameDescription
Public methodBarrier(Int32)Initializes a new instance of the Barrier class.
Public methodBarrier(Int32, Action<Barrier>)Initializes a new instance of the Barrier class.
Top

  NameDescription
Public propertyCurrentPhaseNumberGets the number of the barrier's current phase.
Public propertyParticipantCountGets the total number of participants in the barrier.
Public propertyParticipantsRemainingGets the number of participants in the barrier that haven’t yet signaled in the current phase.
Top

  NameDescription
Public methodAddParticipantNotifies the Barrier that there will be an additional participant.
Public methodAddParticipantsNotifies the Barrier that there will be additional participants.
Public methodDispose()Releases all resources used by the current instance of the Barrier class.
Protected methodDispose(Boolean)Releases the unmanaged resources used by the Barrier, and optionally releases the managed resources.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodRemoveParticipantNotifies the Barrier that there will be one less participant.
Public methodRemoveParticipantsNotifies the Barrier that there will be fewer participants.
Public methodSignalAndWait()Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well.
Public methodSignalAndWait(CancellationToken)Signals that a participant has reached the barrier and waits for all other participants to reach the barrier, while observing a cancellation token.
Public methodSignalAndWait(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.
Public methodSignalAndWait(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.
Public methodSignalAndWait(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.
Public methodSignalAndWait(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.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

The following example shows how to use a barrier:

Windows Phone OS

Supported in: 8.1, 8.0

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.

Show:
© 2014 Microsoft