Sometimes when we are dealing with multithreading application, we need to lock some threads and waiting for another thread finished execution, in order to do that it needs some lock mechanism to lock other threads . So, in this post we have a solution that we can use AutoResetEvent class to block threads from execution. AutoResetEvent is a class to control lock mechanism and guarantee that after it is set, it will allow only one thread to continue, then reset automatically (become lock again). There is also another class named ManualResetEvent, which it concept is similar to AutoResetEvent class, however, the difference is we need to reset the lock mechanism manually. So, it means that it will allows threads at the same time to continue until we tell it to stop (reset it). By the way, in this post I would like to talk about AutoResetEvent class only. The usage scenario for this class is easy to follow as described in the following website:
Useful for multithreading application, it can help to stop main thread to wait for child threads (Tasks).
ReplyDelete