title: Open new window "The calling thread must be STA"
body: <p>I know that there is lots of questions about "The calling thread..." but the way I tried didn´t solve my problem, and I know that I have to include a thread call but I don´t know where.</p>
  
  <p>So, I create a mailItem and add the send and close event handler as below, if the mail item is closed I do nothing, if the mail item is sent I have to open a window to user to register a sort of history.</p>
  
  <p>The error occurs when I try to create the window to register the history.</p>
  
  <p>Step 1:</p>
  
  <pre><code>((Microsoft.Office.Interop.Outlook.ItemEvents_10_Event)mailItem).Send += new Microsoft.Office.Interop.Outlook.ItemEvents_10_SendEventHandler(EmailEnviado);
  
  ((Microsoft.Office.Interop.Outlook.ItemEvents_10_Event)mailItem).Close += new Microsoft.Office.Interop.Outlook.ItemEvents_10_CloseEventHandler(EmailCancelado);
  </code></pre>
  
  <p>Step 2</p>
  
  <pre><code>mailItem.Display();
  </code></pre>
  
  <p>Step 3</p>
  
  <pre><code>private void EmailEnviado(ref bool 
  {
             List&lt;int&gt; listaPendenciaId = new List&lt;int&gt;();
  
              foreach (Pendencia pendencia in this.listaPendencia)
              {
                  if (pendencia.IsSelecionado)
                  {
                      listaPendenciaId.Add(pendencia.
              System.Windows.Window historicoEmailCadastro = new System.Windows.Window
                      {
                          Title = "Cadastro de Histórico de Email",
                          Content = new HistoricoEmailCadastro(listaPendenciaId),
                          Width = 249,
                          Height = 213,
                          ResizeMode = ResizeMode.NoResize
                      };
  
              historicoEmailCadastro.ShowDialog();
  }
  </code></pre>
  
  <p>Thanks in advance.</p>