OpenFileDialog.ShowDialog()申请冻结C# [英] OpenFileDialog.ShowDialog() freezing application c#
问题描述
可能重复:结果
的 C#,WPF - 打开文件对话框不会出现
块引用>
我试图让约翰·亨特的指南,以C#的JDEdit应用程序和面向对象。不过,我把所有的代码都像他那样,我的申请被冻结了,每当我尝试使用ShowDialog的()。我没有收到任何投诉,编译器,所以我不知道发生了什么事。
这是我想要实现的方法。检查条件时冻结。我不认为该计划的其余部分应该是必要的张贴。
私人无效的open(){
//仍在工作
如果(ofd.ShowDialog()== DialogResult.OK){
//从不在这里
字符串文件名= ofd.FileName;
Console.WriteLine(打开:{0},文件名);
textArea.TextChanged - =新的EventHandler
(this.TextArea_TextChanged);
textArea.LoadFile(文件名);
textArea.TextChanged + =新的EventHandler
(this.TextArea_TextChanged);
saveRequired = FALSE;
this.Text =标题+:+文件名;
}
}
谢谢!
< DIV CLASS =h2_lin>解决方案
添加[STAThread]上述主要解决了这个问题。
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!
Adding [STAThread] above Main fixes the problem.
这篇关于OpenFileDialog.ShowDialog()申请冻结C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!