lock keyword basically provides a shortcut to Enter method of Monitor class.
Monitor is used to provide thread synchronization.It means till the Thread in which the method is being used finishes its task, no other thread can access the object.
It is compiled into
See the MSIL of the assembly.
We can write much more code and perform customization in the try block.
Asked In: Many Interviews |