title: Locking critical section in object used across multiple threads
body: <p>I've got a class that is instantiated within any number of threads that are spooled up as needed.  This means that any number of instantiated versions of this class can be used at any one time, and there's a portion of this class that needs to be locked to prevent concurrent access.</p>
  
  <p>To prevent data issues between the various threads, I needed a way to lock a section of code from the other instantiated versions of the class in other threads.  Since there can be multiple instantiated versions of this class running around, I can't just use a private member variable to lock (and I know not to use the Type, or anything publicly accessible); so I used a private static member variable.</p>
  
  <p>Is that a reasonable approach to this problem?  Or is there a better solution?</p>
  
  <p>Sample code below:</p>
  
  <pre><code>public class MyClass
    {
      private static object LockingVar = new object();
  
      public void MyPublicMethod()
      {
        lock (LockingVar)
        {
           // Do some critical code
        }
    }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>MyPublicMethod is making calls to a local SQLExpress instance, it can perform selects in addition to updates and inserts, so it needs to finish before another thread gets in there and mucks it up.</p>