运行时提示次错误:发生了 System.Threading.ThreadStateException
图片如下,这样的错误怎样修改啊?

解决方案 »

  1.   

    当线程处于对于方法调用来说无效的 ThreadState 时引发的异常。
      

  2.   

    http://technet.microsoft.com/zh-cn/windows/ms241609(VS.90).aspx
      

  3.   


    错误出现在这一句
    if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
      

  4.   

    在main函数前加[STAThreadAttribute]属性
    STAThreadAttribute---- 指示应用程序的 COM 线程模型是单线程单元 (STA)。
     
    MTAThreadAttribute---- 指示应用程序的 COM 线程模型是多线程单元 (MTA)。
     
    将此属性应用于入口点方法(C# 和 Visual Basic 中的 Main() 方法)。它们对其他方法无效。
     
    示例:
     
    [STAThread]
     
    public static void main(){......}
     
    或[MTAThread]
     
    public static void main(){......}在调用ole之前,main函数必须被指定为单线程。