C# provides keyword lock for synchronized access.  

A good practice is to create a private object for locking purpose. For example,

public class LockExample

{

    private object syncObject = new object();

 

    public void SynchronizedMethod()

    {

        lock (syncObject)

        {

        }

}
}

It may make sense to create a class just for locking purpose:

using System;

 

class LockClass : object { };

 

public class LockExample

{

    private object syncObject = new LockClass();

 

    public void SynchronizedMethod()

    {

        lock (syncObject)

        {

        }

    }

}

The advantage of the second approach, is that you can easily tell how many lock objects you have used in your project using SOS command “!dumpheap -mt”.