@Reed provides an elegant solution if you need to wait for multiple threads.
You might not want to use Monitor for this. As @Reed noted, an event would be enough and provide the cleanest and most understandable solution that meets the requirements of your code.
The overhead of using real operating system synchronization primitives, most likely, will not matter in your case and using, for example, Monitor will provide only decreasing returns due to much higher complexity.
With that said, an implementation using Monitor and signaling is presented here.
You can use the lock-protected bool flag to indicate that you are finished and cannot wait in this case. (A)
If you really start a new thread in Function2() , where the comments point and use lock() around WaitOne() and Release() , you don't need a flag at all. (IN)
A using the flag:
class Program { static object syncRoot = new object();
B, starting the thread from Function1 :
class Program { static object syncRoot = new object(); static byte b; public static byte Function1() { lock (syncRoot) {
source share