WaitHandles

System.Threading.WaitHandle is a class that inherits from the MarshalByRefObject class and is used to synchronize threads that are running in an application. Blocking and signaling are used to synchronize threads using wait handles. Threads can be blocked by calling any of the methods of the WaitHandle class. They are released, depending on the type of signaling construct that is selected. The methods of the WaitHandle class are as follows:

  • WaitOne: Blocks the calling thread until it receives a signal from the wait handles that it's waiting for.
  • WaitAll: Blocks the calling thread until it receives a signal from all of the wait handles it's waiting for.

The following is an example that shows us how WaitAll works:

public static ...

Get Hands-On Parallel Programming with C# 8 and .NET Core 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.