Mutex are using a name so you could even ensure a resource is accessed exclusively accross multiple EXE files written using various languages while lock is inside your app only.
The lock construct is faster and more convenient. Mutex, though, has a place in that its lock can span applications in different processes on the computer.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
68 Points
240 Posts
Mutex and lock keyword
Jan 31, 2018 07:39 PM|vinodkpasi|LINK
What is the difference between Mutex and lock keyword?
All-Star
48280 Points
17983 Posts
Re: Mutex and lock keyword
Jan 31, 2018 07:57 PM|PatriceSc|LINK
Hi,
Mutex are using a name so you could even ensure a resource is accessed exclusively accross multiple EXE files written using various languages while lock is inside your app only.
https://www.onlinebuff.com/article_understand-monitor-vs-mutex-vs-semaphore-vs-semaphoreslim-onlinebuff_60.html seems to discuss all that quite well.
You had also a very good resource about C# threading but can't find it right now...
Edit; found it at www.albahari.com/threading/
Star
8670 Points
2882 Posts
Re: Mutex and lock keyword
Feb 01, 2018 02:45 AM|Cathy Zou|LINK
Hi vinodkpasi
The lock construct is faster and more convenient. Mutex, though, has a place in that its lock can span applications in different processes on the computer.
http://www.c-sharpcorner.com/UploadFile/1d42da/thread-locking-in-C-Sharp/
A Mutex is like a C# lock, but it can work across multiple processes. In other words, Mutex can be computer-wide as well as application-wide.
http://www.c-sharpcorner.com/UploadFile/1d42da/threading-with-mutex/
VS:
A lock is specific to the AppDomain, while Mutex to the Operating System allowing you to perform cross-process locking and synchronization.
https://abhijit-k-adhikari.me/2012/04/17/lock-monitor-mutex-semaphore/
Best regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.