title: Threading in my windows form app is still freezing my UI
body: <p><strong>Background</strong></p>
  
  <p>Currently working on a windows form app which I asked to create.  I have ran into an issue where the UI freezes when a resource intensive process is being called.  I am currently using threading from which I understand is used to prevent the UI from freezing and taking over the entire pc.</p>
  
  <p><strong>Question</strong> </p>
  
  <p>Currently when I am using threading to call a method in my base class which is to open a file that is located on a remote server.  This method has a delay of approximately 30 to 45 seconds.  I am creating my background thread and invoking it to start.  When invoked to start if fires, however when it fired it would not wait for my thread to complete basically giving me a null exception.  So after some digging I found that in order to wait for the thread to complete you had to invoke the <code>.Join()</code>.  However when the Join is invoked it froze my UI completely.  So my ingenuity tried to create a work around and created a while loop that would until the thread is no longer alive and continue.  However, this also froze the UI.  So am I missing something? That is not mention in <a href="https://msdn.microsoft.com/en-us/library/ck8bc5c6(v=vs.110).aspx" rel="nofollow noreferrer">MSDN Doc</a></p>
  
  <p><strong>Code Sample</strong></p>
  
  <pre><code>class BaseClass
  {
      public CWClient ClientFileContext(string clientFile, bool compress)
      {
          Client clientContext = null;
          try
          {
              if (compress == true)
              {
                  clientContext = appInstance.Clients.Open2(clientFile, superUser, passWord, OpenFlags.ofCompressed);
              }
              else
              {
                  clientContext = appInstance.Clients.Open2(clientFile, superUser, passWord, OpenFlags.ofNone);
              }
          }
          catch (Exception ex)
          {
              //TODO
          }
          return clientContext;
      }
  }
  
    public partial class Form1 : Form
    {
     private void button1_Click(object sender, EventArgs e) 
      {
          BaseClass wpSec = new BaseClass();
          CWClient client = null;               
  
          Thread backgroundThread = new Thread(
              new ThreadStart(() =&gt;
              {
                  client = wpSec.ClientFileContext(selectedFileFullPath, true);
              }
          ));
          backgroundThread.Start();
          //backgroundThread.Join(); &lt;&lt; Freezes the UI
          var whyAreYouNotWorking = "Stop";
      }
    }
  </code></pre>
  
  <p><strong>Work around I tried</strong></p>
  
  <pre><code> while (backgroundThread.IsAlive == true)
   {
      for (int n = 0; n &lt; 100; n++)
      {
         Thread.Sleep(500);
         progressBar1.BeginInvoke(new Action(() =&gt; progressBar1.Value = n));
      }
   }
    // This also freezes the UI
  </code></pre>