title: Lock used in different methods
body: <p>I have a question about locking and whether I'm doing it right.</p>
  
  <p>In a class, I have a static lock-object which is used in several methods, assume access modifiers are set appropriately, I won't list them to keep it concise.</p>
  
  <pre><code>class Foo
  { 
     static readonly object MyLock = new object();
  
     void MethodOne()
     {
         lock(MyLock) { 
            // Dostuff
         }
     }
  
     void MethodTwo()
     {
         lock(MyLock) { 
            // Dostuff
         }
     }
  }
  </code></pre>
  
  <p>Now, the way I understand it, a lock guarantees only one thread at a time will be able to grab it and get into the DoStuff() part of one method.</p>
  
  <p>But is it possible for the same thread to call MethodOne() and MethodTwo() at the same time? Meaning that he uses the lock he has gotten for both methods?</p>
  
  <p>My intended functionality is that every method in this class can only be called by a single thread while no other method in this class is currently executing.</p>
  
  <p>The underlying usage is a database class for which I only want a single entry and exit point. It uses SQL Compact, so if I attempt to read protected data I get all sorts of memory errors.</p>
  
  <p>Let me just add that every once and a while a memory exception on the database occurs and I don't know where it's coming from. I thought it was because of one thread doing multiple things with the database before completing things, but this code seems to work like it should.</p>