I suspect your problem is that your lock is an instance member and not static (level type).
Assuming each thread has its own instance of the containing class, then it will also have its own instance of your locker, which is not what you want.
Try this expression instead:
private static readonly object locker = new object();
The inclusion of the static keyword now makes this instance of the object existing at the type level, that is, shared in all instances of your class.
Rob levine
source share