title: C# Thread - STAThreadAttribute exception
body: <p>I will try explain as much as i can.
  Basically i'm using Global Hotkeys in my Formless System Tray Application. 
  To do so i'm using this hotkey manager: <a href="https://stackoverflow.com/questions/3654787/global-hotkey-in-console-application/3654821#3654821">Global hotkey in console application</a> 
  When calling the hotkeys i started receiving this exception:</p>
  
  <blockquote>
    <p>Current thread must be set to single thread apartment (STA) mode
    before OLE calls can be made. Ensure that your Main function has
    STAThreadAttribute marked on it.</p>
  </blockquote>
  
  <p>The way i 'fixed' the exception is: <a href="https://stackoverflow.com/a/6373700/6329242">https://stackoverflow.com/a/6373700/6329242</a>
  My global hotkeys started working except one and I am getting the same exception for it. Couldn't really find a way to fix it.</p>
  
  <p>Here's how i call them: </p>
  
  <pre><code>      static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e)
      {
          switch (e.Key)
          {
              case Keys.D1:
                  CaptureAreaOfScreenForm caos2 = new CaptureAreaOfScreenForm();
                  var thread1 = new Thread(new ParameterizedThreadStart(param =&gt; { caos2.Show(); }));
                  thread1.SetApartmentState(ApartmentState.STA);
                  thread1.Start();
                  break;
              case Keys.D2:
                  CaptureWorkingArea cwa2 = new CaptureWorkingArea();
                  var thread2 = new Thread(new ParameterizedThreadStart(param =&gt; { cwa2.CaptureTheWorkingArea(); }));
                  thread2.SetApartmentState(ApartmentState.STA);
                  thread2.Start();
                  break;
              case Keys.D3:
                  CaptureFullScreen cfs2 = new CaptureFullScreen();
                  var thread3 = new Thread(new ParameterizedThreadStart(param =&gt; { cfs2.CaptureDesktop(); }));
                  thread3.SetApartmentState(ApartmentState.STA);
                  thread3.Start();
                  break;
              case Keys.D4:
                  CaptureAllScreens cas2 = new CaptureAllScreens();
                  var thread4 = new Thread(new ParameterizedThreadStart(param =&gt; { cas2.CaptureScreens(); }));
                  thread4.SetApartmentState(ApartmentState.STA);
                  thread4.Start();
                  break;
              case Keys.D5:
                  UploadFromFile uff2 = new UploadFromFile();
                  var thread5 = new Thread(new ParameterizedThreadStart(param =&gt; { uff2.UploadFile(); }));
                  thread5.SetApartmentState(ApartmentState.STA);
                  thread5.Start();
                  break;
          }
          //collect the garbage
          GC.Collect();
      }
  </code></pre>
  
  <p>(case Keys.D1 is the problem). The difference between the problematic one and the others is i am calling a form class. (others are working fine)</p>
  
  <p>P.S. I am new to programming if I can add something that would help solving it or anything more tell me to do so. Thanks.</p>