【问题标题】:OpenFileDialog.ShowDialog() freezing application c# [duplicate]OpenFileDialog.ShowDialog()冻结应用程序c#[重复]
【发布时间】:2012-10-08 06:38:22
【问题描述】:

可能重复:
C#, WPF - OpenFileDialog does not appear

我正在尝试制作 John Hunt 的 C# 和面向对象指南中的“JDEdit”应用程序。但是,我像他一样输入了所有代码,每当我尝试使用 ShowDialog() 时,我的应用程序就会冻结。我没有收到任何编译器投诉,所以我不确定发生了什么。

这是我正在尝试实施的方法。检查条件时它会冻结。我认为程序的其余部分不需要发布。

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;
    }
}

谢谢!

【问题讨论】:

  • 您尝试过加载文件吗?
  • 我想我应该添加对话框永远不会打开,所以我不能点击任何东西,我认为它可能是那个帖子的副本。我现在正在检查它以尝试找到解决方案。
  • 抱歉重复的问题,没有看到那个问题。在 Main 上方添加 [STAThread] 修复了它。

标签: c#


【解决方案1】:

在 Main 上方添加 [STAThread] 可以解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多