+1 vote
in Dot Net by

Explain LockMonitors, and Mutex Object in Threading

1 Answer

0 votes
by

 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.

Monitor.Enter(ObjA);
try
{
}
Finally {Monitor.Exit(ObjA));}

Related questions

+1 vote
asked Jun 25, 2019 in Dot Net by Venkatshastri
+1 vote
asked Jun 25, 2019 in Dot Net by Venkatshastri
...