问题
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