What is the Mutex and semaphore In c#? where we need to implement?

Jaswant Agarwal picture Jaswant Agarwal · Oct 12, 2009 · Viewed 31.8k times · Source

What is the Mutex and semaphore in C#? Where we need to implement?

How can we work with them in multithreading?

Answer

bobbymcr picture bobbymcr · Oct 12, 2009

You should start at MSDN.

Generally you only use a Mutex across processes, e.g. if you have a resource that multiple applications must share, or if you want to build a single-instanced app (i.e. only allow 1 copy to be running at one time).

A semaphore allows you to limit access to a specific number of simultaneous threads, so that you could have, for example, a maximum of two threads executing a specific code path at a time.