When implementing a lock, I used to create a private object inside of my class:
If I want to be sure that it is locked in the thread that created my class:
private object Locker = new object();
If I want to be sure that it will be locked for all threads inside my application:
private static object Locker = new object();
But here: Why does the lock object have to be static?
and in a number of other questions, everyone says that the object has to be readonly
. I haven't found the reason - not even in MSDN or JavaDoc.
As I use this kind of construction quite often, could someone explain to me why should I use readonly
?
Thanks!