1

Possible Duplicate:
C#, WPF - OpenFileDialog does not appear

I'm trying to make the "JDEdit" application from John Hunt's Guide to C# and Object Orientation. However, I put in all the code like he did and my application is freezing up whenever I try to use ShowDialog(). I'm not getting any compiler complaints so I'm not sure what's going on.

This is the method I'm trying to implement. It freezes when checking the conditional. I don't think the rest of the program should be necessary to post.

private void Open() {

    // still working

    if (ofd.ShowDialog() == DialogResult.OK) {

        // never makes it here

        string filename = ofd.FileName;
        Console.WriteLine("Open: {0}", filename);
        textArea.TextChanged -= new EventHandler
            (this.TextArea_TextChanged);
        textArea.LoadFile(filename);
        textArea.TextChanged += new EventHandler
            (this.TextArea_TextChanged);
        saveRequired = false;
        this.Text = title + ": " + filename;
    }
}

Thanks!

Community
  • 1
  • 1
will
  • 1,491
  • 1
  • 19
  • 28
  • Have you tried to load a file? – Lior Oct 07 '12 at 22:30
  • I guess I should have added that the dialog never opens so I can't click anything and I think it might be a duplicate of that post. I'm checking over it right now to try and find a solution. – will Oct 07 '12 at 22:35
  • Sorry for the duplicate question, didn't see that one. Adding [STAThread] above Main fixed it. – will Oct 07 '12 at 22:37

1 Answers1

3

Adding [STAThread] above Main fixes the problem.

will
  • 1,491
  • 1
  • 19
  • 28