title: C# lock statement, what object to lock on?
body: <p>I have 3 questions that I need help with.</p>
  
  <ol>
  <li><p>What are the correct objects/references to be passed as <code>lock</code> statement parameter? I've seen a lot of sample codes and I noticed that the objects/references passed in could possibly be non related to the current class or any other class in the program as long as the access modifier <code>static</code> is non public? E.g.:</p>
  
  <pre><code>private Object anyObj = new Object();
  lock(anyObj){.....}
  
  private static readonly object Locker = new object();
  lock(Locker){.....}
  </code></pre>
  
  <p>It just doesn't make sense to me.</p></li>
  <li><p>I found a sample code in MSDN about multi threading that uses <code>lock</code> statements too. In the sample there are two <code>try</code>/<code>catch</code> blocks with the <code>Monitor.Wait()</code> within it. If I understand the logic correctly, the <code>readerFlag</code> will forbid the program to ever enter the <code>try</code>/<code>catch</code> block at all.<br/>The code is example 2 from here:<br/>
  <a href="http://msdn.microsoft.com/en-us/library/aa645740(v=vs.71).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/aa645740(v=vs.71).aspx</a></p></li>
  <li><p>How do I run a thread that runs in the background as long as the Windows Form is active?</p></li>
  </ol>