Multi-threading concept and lock in c#

Posted by Neeraj on Stack Overflow See other posts from Stack Overflow or by Neeraj
Published on 2012-04-14T09:46:26Z Indexed on 2012/04/14 11:28 UTC
Read the original article Hit count: 185

Filed under:
|
|

I read about lock, though not understood nothing at all. My question is why do we use a un-used object and lock that and how this makes something thread-safe or how this helps in multi-threading ? Isn't there other way to make thread-safe code.

public class test {
    private object Lock { get; set; }

    ...
    lock (this.Lock) { ... }
    ...
}

Sorry is my question is very stupid, but i don't understand, although i've used it many times.

© Stack Overflow or respective owner

Related posts about c#

Related posts about multithreading