title: OpenFileDialoug Current Thread Must Be STA before OLE calls made
body: <p>Can someone explain to me what this error I'm seeing is?</p>
  <p>Current thread must be set to single thread apartment (STA) mode before OLE calls can be made.</p>
  <p>Specifically, I'm trying to open the SaveFileDialog/OpenFileDialog within C++/CLI on a form.</p>
  <pre><code>SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
  saveFileDialog1-&gt;ShowDialog();
      if (saveFileDialog1-&gt;ShowDialog() == System::Windows::Forms::DialogResult::OK)
      {
          s = saveFileDialog1-&gt;OpenFile();
          }
          s-&gt;Close();
      }
  </code></pre>
  <p>The error that is throwing is</p>
  <blockquote>
  <p>An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll</p>
  <p>Additional information: 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. This exception is only raised if a debugger is attached to the process.</p>
  </blockquote>
  <p>I'm not really familiar with what this error is saying. I know just a bit about threading, but I'm not sure how threading would be an issue here. I've seen some people reference things like STAThread without providing a clear explanation as to what it does, and Microsoft's documentation makes no mention of having this exception thrown when calling SaveFileDialog/OpenFileDialog, or how to handle it.</p>
  <p>Thanks!</p>