title: When should I set a thread to ApartmentState.STA?
body: <p>I am curious to know when STA/MTA are used in C# .net?</p>
  
  <pre><code>using (ManualResetEventSlim mre = new ManualResetEventSlim(false)) 
  {       
      Thread _STAThread = new Thread(new ThreadStart(() =&gt;                 
          {
               globalComObject = new ComClass();                     
               mre.Set();                     
               try                     
               {                         
                    Thread.CurrentThread.Join();
               }
               catch (ThreadAbortException)                     
               { } 
           }));
       _STAThread.SetApartmentState(ApartmentState.STA);                    
       _STAThread.IsBackground = true;                 
       _STAThread.Start();                 
       mre.Wait(); 
  } 
  </code></pre>