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

SignalAndWait() public method

Signals that a participant has reached the Barrier and waits for all other participants to reach the barrier as well, using a T:System.TimeSpan to measure the time interval, while observing a .
is a negative number /// other than -1 milliseconds, which represents an infinite time-out. /// The method was invoked from within a post-phase action, the barrier currently has 0 participants, /// or the barrier is being used by more threads than are registered as participants. /// has been /// canceled. The current instance has already been /// disposed.
public SignalAndWait ( TimeSpan timeout, CancellationToken cancellationToken ) : Boolean
timeout TimeSpan A that represents the number of /// milliseconds to wait, or a that represents -1 milliseconds to /// wait indefinitely.
cancellationToken CancellationToken The to /// observe.
return Boolean
        public Boolean SignalAndWait(TimeSpan timeout, CancellationToken cancellationToken)
        {
            Int64 totalMilliseconds = (Int64)timeout.TotalMilliseconds;
            if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
            {
                throw new System.ArgumentOutOfRangeException(nameof(timeout), timeout,
                    SR.Barrier_SignalAndWait_ArgumentOutOfRange);
            }
            return SignalAndWait((int)timeout.TotalMilliseconds, cancellationToken);
        }

Same methods

Barrier::SignalAndWait ( TimeSpan timeout ) : Boolean
Barrier::SignalAndWait ( int millisecondsTimeout ) : bool
Barrier::SignalAndWait ( int millisecondsTimeout, CancellationToken cancellationToken ) : bool
Barrier::SignalAndWait ( ) : void
Barrier::SignalAndWait ( CancellationToken cancellationToken ) : void

Usage Example

Example #1
1
        /// <summary>
        /// Download all the images for the current session
        /// </summary>
        public void DownloadAllTreatmentImages()
        {
            Barrier barrier = new Barrier(_patient.PatientTreatment.TrainingList.Count + 2);

            Task treatmentThread = new Task(() =>
            {
                //Downloading all thumbs in treatment
                DownloadTreatment();

                barrier.SignalAndWait();
            });
            treatmentThread.Start();

            foreach(Training t in _patient.PatientTreatment.TrainingList)
            {
                Task tt = new Task(() =>
                {
                    DownloadTraining(_patient.PatientTreatment.TrainingList.IndexOf(t));
                    barrier.SignalAndWait();
                });
                tt.Start();

            }

            barrier.SignalAndWait();
            barrier.Dispose();
        }
All Usage Examples Of System.Threading.Barrier::SignalAndWait