Explore how to use Countdown, which counts and waits for the number of signals it's supposed to wait for before releasing execution.
- [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 also print the task ID…and say Task.CurrentId…
Released
4/2/2018- Thread safety and affinity
- Signaling
- Task Parallel Library (TPL) basics
- PLINQ introduction
- Task-based Asynchronous Pattern (TAP)
Share this video
Embed this video
Video: Signaling: Countdown