title: How to stop thread when Lock is encountered?
body: <p>I have the following code that starts some threads:</p>
  
  <pre><code>    List&lt;Stuff&gt; lNewStuff = new List&lt;Stuff&gt;();
  
      // populate lNewStuff
  
      for (int i = 0; i &lt; accounts.Length; i++)
      {
          Account aTemp = _lAccounts.Find(item =&gt; item.ID == accounts[i]);
  
          Thread tTemp = new Thread(() =&gt; aTemp.ExecuteMe(lNewStuff));
          tTemp.Start();     
      }
  </code></pre>
  
  <p>Then in the Account class you have the ExecuteMe method that has a lock:</p>
  
  <pre><code>    public class Account
      {
          private Object lockThis = new Object();
  
          public void ExecuteMe(List&lt;Stuff&gt; lNewStuff)
          {
              //Ensure only one thread at a time can run this code
              lock (lockThis)
              {
                  //main code processing
              }
          }
      }
  </code></pre>
  
  <p>Now, sometimes the thread starts with lNewStuff == null since it sometimes does not find any New Stuff with the Account ID. This is normal for this project. The thread should always try to run but when null I want this thread to die and not wait when a lock is encountered.</p>
  
  <p>So specifically: </p>
  
  <p>If lNewStuff is null and there is a lock then terminate the thread. (how to do this?)</p>
  
  <p>If lNewStuff is null and there is no lock then run normally (does this already)</p>
  
  <p>If lNewStuff is not null and there is a lock then wait for the lock to finish (does this already)</p>
  
  <p>if lNewStuff is not null and there is no lock then run normally (does this already)</p>