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

RemoveParticipant() public method

Notifies the Barrier that there will be one less participant.
The barrier already has 0 /// participants. /// The method was invoked from within a post-phase action. /// The current instance has already been /// disposed.
public RemoveParticipant ( ) : void
return void
        public void RemoveParticipant()
        {
            RemoveParticipants(1);
        }

Usage Example

コード例 #1
0
        static void Main(string[] args)
        {
            // create a barrier
            Barrier barrier = new Barrier(2);

            // create a task that will complete
            Task.Factory.StartNew(() => {
                Console.WriteLine("Good task starting phase 0");
                barrier.SignalAndWait();
                Console.WriteLine("Good task starting phase 1");
                barrier.SignalAndWait();
                Console.WriteLine("Good task completed");
            });

            // create a task that will throw an exception
            // with a selective continuation that will reduce the
            // particpant count in the barrier
            Task.Factory.StartNew(() => {
                Console.WriteLine("Bad task 1 throwing exception");
                throw new Exception();

            }).ContinueWith(antecedent => {
                // reduce the particpant count
                Console.WriteLine("Reducing the barrier participant count");
                barrier.RemoveParticipant();
            }, TaskContinuationOptions.OnlyOnFaulted);

            // wait for input before exiting
            Console.WriteLine("Press enter to finish");
            Console.ReadLine();
        }
All Usage Examples Of System.Threading.Barrier::RemoveParticipant