title: ExcelDna: Async: The calling thread must be STA
body: <p>I'm working with ExcelDna and async functions. If there's an exception in the async:d code I want to show a fancy WPF error window. My problem is that I'm getting the error "The calling thread must be STA, because many UI components require this." How can I solve this?  </p>
  
  <pre><code>    [ExcelFunction(Description = "", Category = "")]
      public static async Task&lt;object&gt; /*string*/ Foo(CancellationToken ct)
      {
          try
          {
              return await Task.Run(async () =&gt;
              {
                  await Task.Delay(1000, ct);
                  throw new Exception("BOO");
                  return "HelloWorld";
              }, ct2.Token);
          }
          catch (Exception e)
          {
              return ShowWpfErrorWindowThatRequiresSTA(e);
          }
      }
  </code></pre>