ThreadStateException c#

不打扰是莪最后的温柔 提交于 2019-12-10 18:38:46

问题


I have a ThreadStateException that i need to have STAThread... The problem appeared yesterday, I even ckecked previous versions from my git repo (which were 100% working) - now they're not.

Code for main:

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new ClientList());
}

And ClientList form method:

private void button2_Click(object sender, EventArgs e)
{
    [...]
    OpenFileDialog ofd = new OpenFileDialog();
    DialogResult result = ofd.ShowDialog();
    [...]
}

Any idea why STA won't work?

EDIT: In new (test) application everything works fine. Only this project throws an exception on OpenFileDialog.

EDIT 2: The getAppartmentState shows that app is in MTA from the very first line of Main. Is [STAThread] ignored?

来源:https://stackoverflow.com/questions/11560479/threadstateexception-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!