From the course: Advanced Threading in C#
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Signaling: Countdown - C# Tutorial
From the course: Advanced Threading in C#
Signaling: Countdown
- [Instructor] So next we have Countdown, which is a construct for synchronization. That is signaled when its count reaches zero, so it's very similar to what you saw earlier with AutoResetEvent and ManualResetEvent, except this time it's going to wait for the worker threads signal to be called x amount of times. So if we have five different threads that have a Countdown, until it calls the signal method those five times, it'll continue to wait on it. And that number could vary according to our needs. So we'll create CountdownEvent and then resolve the reference using System.Threading, I'm going to call it CaztonCountdown and then give it the limit. So in this case we could say five is my initial count, needs to be five. Next we'll start a task and then DoSomething, resolve the method, and we can copy this thing five times. So this way we'll have five different threads that have been spawned. We don't really need it to sleep for a long time so I'll say 250 milliseconds and then I can…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.