title: Why do C# OpenFileDialogs get created off the main GUI thread?
body: <p>I have a c# winforms app that hangs occasionally and I was told that we should make sure we're not opening any windows off the main GUI thread. I fired up Spy++ and noticed that when we open the OpenFileDialog at the beginning of the client session, that dialog exists on another thread, even though the code path is running on the main GUI thread.</p>
  
  <p>Then, after the window is closed, the window still shows up in Spy++ as being on a worker thread. This happens even if we enclose usage of the OpenFileDialog inside a using statement. So it seems that disposing of the dialogue doesn't actually get rid of the Window, which is weird.</p>
  
  <p>Here's the actual code</p>
  
  <pre><code>                if (filename == String.Empty)
              {
                  using (var openFileDialog = new OpenFileDialog
                      {
                          Filter = string.Format(MessageStrings["DialogFormat"]),
                          Title = MessageStrings["OpenDialogTitle"]
                      })
                  {
                      if (openFileDialog.ShowDialog() != DialogResult.OK || openFileDialog.FileName == String.Empty)
                          return false;
                      filename = openFileDialog.FileName;
                  }
              }
  </code></pre>