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;
}