System.Threading.Barrier.Barrier C# (CSharp) Method

Barrier() public method

Initializes a new instance of the Barrier class.
The postPhaseAction delegate will be executed after all participants have arrived at the barrier in one phase. The participants will not be released to the next phase until the postPhaseAction delegate has completed execution.
is less than 0 /// or greater than .
public Barrier ( int participantCount, Action postPhaseAction ) : System.Diagnostics
participantCount int The number of participating threads.
postPhaseAction Action The to be executed after each /// phase.
return System.Diagnostics
        public Barrier(int participantCount, Action<Barrier> postPhaseAction)
        {
            // the count must be non negative value
            if (participantCount < 0 || participantCount > MAX_PARTICIPANTS)
            {
                throw new ArgumentOutOfRangeException(nameof(participantCount), participantCount, SR.Barrier_ctor_ArgumentOutOfRange);
            }
            _currentTotalCount = (int)participantCount;
            _postPhaseAction = postPhaseAction;

            //Lazily initialize the events
            _oddEvent = new ManualResetEventSlim(true);
            _evenEvent = new ManualResetEventSlim(false);

            // Capture the context if the post phase action is not null
            if (postPhaseAction != null)
            {
                _ownerThreadContext = ExecutionContext.Capture();
            }

            _actionCallerID = 0;
        }

Same methods

Barrier::Barrier ( int participantCount ) : System.Diagnostics