C# (C Sharp) - How to symchronize the access to a ressource using Mutex?
The Mutex class provides very useful functionality when you use multiple threads and you need to synchronize the access to a given ressource. Imagine the situation when you have multiple threads which try to write in a file on the same time - if you don't synchronize the access an exception will be thrown. You can do such a synchronization by simply using a Mutex. public static Mutex WriteFileMutex=new Mutex(); ... mut.WaitOne(); ... code to write in the file should be placed here .. mut.ReleaseMutex();
Category: | C# (C Sharp) |
<< Go back