How to use Synchronization lock in C#?

Posted by SheoNarayan under C# category on | Views : 10194
Synchronization lock can be used in C# to ensure that only one thread at at time can enter the locked section of the code. The syntax is pretty simple.

  lock (this) 
// do your work

Here, "this" is the lock identifier and the current instance of the class. You can create a separate object and specify as the lock identifier too.

Comments or Responses

Login to post response