Ever wondered what the difference is…

… between using a lock statement, versus using a Montior.Enter / Monitor.Exit clause? Actually there’s a few, but the main one is that a lock statement is inherently thread safe, where-as a Montior is not. So -


    try {
        Monitor.Enter(_lock);
        DoThreadSafeCode();

    } finally {
        Monitor.Exit(_lock);
    }

is essentially the same as -


    lock (_lock) {
        DoThreadSafeCode();
    }
Posted in .Net by Gerrod at December 4th, 2007.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Quickduck logo