.NET doesn't have semaphores, but it does offer a couple of objects which can do what you want.
The Interlocked class synchronizes access to a protected variable atomically. Meaning that it's Increment & Decrement methods can't be interrupted by another thread.
The Monitor class acts like a critical section, protecting access to a block of code so that only one thread at a time can execute it.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.