Barrier Class

.NET Framework (current version)
 

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

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

System::Object
  System.Threading::Barrier

[ComVisibleAttribute(false)]
[HostProtectionAttribute(SecurityAction::LinkDemand, Synchronization = true, 
	ExternalThreading = true)]
public ref class Barrier : IDisposable

NameDescription
System_CAPS_pubmethodBarrier(Int32)

Initializes a new instance of the Barrier class.

System_CAPS_pubmethodBarrier(Int32, Action<Barrier^>^)

Initializes a new instance of the Barrier class.

NameDescription
System_CAPS_pubpropertyCurrentPhaseNumber

Gets the number of the barrier's current phase.

System_CAPS_pubpropertyParticipantCount

Gets the total number of participants in the barrier.

System_CAPS_pubpropertyParticipantsRemaining

Gets the number of participants in the barrier that haven’t yet signaled in the current phase.

NameDescription
System_CAPS_pubmethodAddParticipant()

Notifies the Barrier that there will be an additional participant.

System_CAPS_pubmethodAddParticipants(Int32)

Notifies the Barrier that there will be additional participants.

System_CAPS_pubmethodDispose()

Releases all resources used by the current instance of the Barrier class.

System_CAPS_protmethodDispose(Boolean)

Releases the unmanaged resources used by the Barrier, and optionally releases the managed resources.

System_CAPS_pubmethodEquals(Object^)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodRemoveParticipant()

Notifies the Barrier that there will be one less participant.

System_CAPS_pubmethodRemoveParticipants(Int32)

Notifies the Barrier that there will be fewer participants.

System_CAPS_pubmethodSignalAndWait()

Signals that a participant has reached the barrier and waits for all other participants to reach the barrier as well.

System_CAPS_pubmethodSignalAndWait(CancellationToken)

Signals that a participant has reached the barrier and waits for all other participants to reach the barrier, while observing a cancellation token.

System_CAPS_pubmethodSignalAndWait(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.

System_CAPS_pubmethodSignalAndWait(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.

System_CAPS_pubmethodSignalAndWait(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.

System_CAPS_pubmethodSignalAndWait(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.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

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:

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1

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.

Return to top
Show: