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

解决方案 »

  1.   

    = =调试信息里不是写的很清楚了嘛...
    你的Main带[STAThread]了吗?
      

  2.   


    如果还不行,在入口程序试试加上[STAThread]
      

  3.   


    如果还不行,在程序入口试试加上[STAThread]
      

  4.   

    [STAThread]
    public void main()
    {}
      

  5.   

    你的Main带[STAThread]了吗? 
    有的
      

  6.   

      System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(OpenFiles));
                th.SetApartmentState(System.Threading.ApartmentState.STA);
                th.Start();
      

  7.   

    难道你那个OpenFiles就不能直接执行吗?放在线程里简直就是自找麻烦。这问题都不止一个人问过,怎么就有人喜欢乱用线程。
    [quote必须将当前线程设置为单线程单元(STA)模式
    你要是这么设置了,那还不如使用Show代替ShowDialog()呢,因为都不会等待阻塞线程。
      

  8.   

    Winform中的控件等多是对以前COM组件的包装,你的子线程要打开一个GUI dialog,也就是说间接用到了COM interop。那些个COM组件都是要求运行在STA线程模型中,so...