title: WatiN: The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer
body: <p>I am calling WatiN from a C# windows service. When I invoke WatiN it throws the following exception. The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer</p>
  
  <p>I have tried starting up a thread and setting the apartment state via </p>
  
  <pre><code>mythread.SetApartmentState(ApartmentState.STA)
  </code></pre>
  
  <p>but that resulted in another error </p>
  
  <p><strong><em>Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.</em></strong></p>
  
  <p>I also tried adding an attribute to the Service entry point.</p>
  
  <pre><code>static class Program
  {
        [STAThread]
        static void Main()
        {
            ...
  </code></pre>
  
  <p>Any ideas? </p>