- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the Mutex class in C#?
The Mutex class in C# is a synchronization primitive that can also be used for interprocess synchronization.
Let us see how to create a new Mutex.
private static Mutex m = new Mutex();
Let us now see how to initialize a new instance of the Mutex class with a Boolean value.
private static Mutex m = new Mutex(true);
Now let us see how to initialize a new instance of the Mutex class with a Boolean value and the name of the Mutex.
Example
using System; using System.Threading; public class Demo { public static void Main() { Mutex mt = new Mutex(false, "NewMutex"); Console.WriteLine("Waiting for the Mutex."); mt.WaitOne(); Console.WriteLine("Owner of the mutex. " + "ENTER is to be pressed to release the mutexand exit."); Console.ReadLine(); mt.ReleaseMutex(); } }
Output
Waiting for the Mutex. Owner of the mutex. ENTER is to be pressed to release the mutex and exit.
- Related Articles
- What is the SortedList class in C#?
- What is the Stack class in C#?
- What is the BitArray class in C#?
- What is the Queue class in C#?
- What is the Hashtable class in C#?
- What is the ArrayList class in C#?
- Mutex vs Semaphore
- What is Proxy Class in C++?
- Deadlock with mutex locks
- What is the class "class" in Java?
- How to use Mutex in Golang?
- What is Regex class and its class methods in C#?
- What is the purpose of the StringBuilder class in C#?
- What is a sealed class in C#?
- What is a static class in C#?

Advertisements