zoukankan      html  css  js  c++  java
  • 在可以调用OLE之前,必须将当前线程设置为单线程单元(STA)模式,请确保您的Main函数带有STAThreadAttribute

    在可以调用OLE之前,必须将当前线程设置为单线程单元(STA)模式,请确保您的Main函数带有STAThreadAttribute

    From博客园(乏mily)
    导入导出功能,在调用ShowDialog时的错误,解决办法如下:

    WinForm窗体的入口点:

            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            private static void Main(String[] args)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new LoginForm());
            }
    

    报错页面程序如下:

    public string importPath=""; //全局变量,用于显示导入文件路劲
    
            private void btnImport_Click(object sender, EventArgs e)
            {
                Thread importThread = new Thread(new ThreadStart(ImportDialog));
                importThread.SetApartmentState(ApartmentState.STA); //重点
                importThread.Start();
                txtImportPath.Text = importPath;
            }
            public void ImportDialog()
            {
                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "Excel文件|*.xls;*.xlsx";
                if (open.ShowDialog() == DialogResult.OK)
                {
                    importPath = open.FileName;
    
                    ReadExcelToTable(importPath);
                    UpdateArea();
                }
            }
    
  • 相关阅读:
    《DSP using MATLAB》Problem 6.17
    一些老物件
    《DSP using MATLAB》Problem 6.16
    《DSP using MATLAB》Problem 6.15
    《DSP using MATLAB》Problem 6.14
    《DSP using MATLAB》Problem 6.13
    《DSP using MATLAB》Problem 6.12
    《DSP using MATLAB》Problem 6.11
    P1414 又是毕业季II
    Trie树
  • 原文地址:https://www.cnblogs.com/Study-Csharp/p/11385302.html
Copyright © 2011-2022 走看看