Jun 25, 2019 in Dot Net

Explain LockMonitors, and Mutex Object in Threading

1 Answer

0 votes
Jun 25, 2019

 Lock keyword ensures that only one thread can enter a particular section of the code at any given time. In the above Example, lock(ObjA) means the lock is placed on ObjA until this process releases it, no other thread can access ObjA.

Mutex is also like a lock but it can work across multiple processes at a time. WaitOne() is used to lock and ReleaseMutex() is used to release the lock. But Mutex is slower than lock as it takes time to acquire and release it.

Monitor.Enter and Monitor.Exit implements lock internally. a lock is a shortcut for Monitors. lock(objA) internally calls.

Finally {Monitor.Exit(ObjA));}

Related questions

+1 vote
Jun 25, 2019 in Dot Net
+1 vote
Jun 25, 2019 in Dot Net