title: Do you need a Sleep before attempting a Thread Join?
body: <p>At the moment I've got a strange release-only crash in my program.  It seems to be throwing a <code>NullReferenceException</code> on <code>webPageLoader[i].Join();</code> but I  doesn’t seem to fail in debug.</p>
  
  <p>Could my problem be related to the fact that the thread has not had the chance to start so therefore can’t be joined? Has anyone got any tips to how I could go about debugging this as it doesn’t seem to manifest in debug at all.</p>
  
  <p>If I put a <code>sleep(50)</code> before <code>webPageLoader[i].Join();</code> it doesn’t seem to crash. But I would expected it to not crash without the <code>sleep</code>.</p>
  
  <pre><code>for (int i = 0; i &lt; pagesToGet; i++)
  {
      crawlContext.vistedURLs.AddURL(CurrentURL);                                
      document[i] = new DocumentToScrape();
      webPageLoader[i] = new Thread(document[i].LoadPage);
      webPageLoader[i].Start(CurrentURL);
  
      if (!crawlContext.unVistedURLs.MoveNext())
      {
          break;
      }
  }
  
  for (int i = 0; i &lt; pagesToGet; i++)
  {
      **webPageLoader[i].Join();**
      if (document[i].Doc != null)
      {
          document[i].Doc = GetSubSetXPath(document[i].Doc, crawlContext.xPath);                      
          if (document[i].Doc != null)
          {
              crawlContext.scrapedUrls = ScrapeURLS(crawlContext.scrapedUrls, document[i]);                                      
          }
          else
          {
              //System.Windows.Forms.MessageBox.Show("Null Page Found");
          }
  
      }
  }
  </code></pre>