Winform 弹出选择文件对话窗口,线程错误!!!
ShowDialog 在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main 函数带有 STAThreadAttribute 标记。 只有将调试器附加到该进程才会引发此异常。
代码如下
private void btnSelect_Click(object sender, EventArgs e)
{
System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(OpenFiles));
Initlv_Excel();
th.Start();
}
private void OpenFiles()
{
openExcelDialog.Filter = "Text File (*.xls)|*.xls";
this.openExcelDialog.ShowDialog();这里报错
string fileName = this.openExcelDialog.FileName;
txtFile.Text = fileName;
FileListBind(fileName);
}