我得到了这段运行.exe的代码
string openEXE = @"C:\Users\marek\Documents\Visual Studio 2012\Projects\tours\tours\bin\Debug\netpokl.exe";
                 Process b = Process.Start(openEXE);
                 b.EnableRaisingEvents = true;
                 b.Exited += (netpokl_Closed);当它关闭时,它会调用netpokl_Closed方法。问题是,当I insert into netpokl_Closed command - this.Close()时,这个异常会上升:Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on
我怎么才能修复它?感谢您的时间和答案。
发布于 2013-08-19 16:53:22
之所以会出现异常,是因为您试图从创建窗体的线程以外的其他线程关闭窗体。这是不允许的。
像这样做
this.Invoke((MethodInvoker) delegate
        {
            // close the form on the forms thread
            this.Close();
        });发布于 2013-08-19 16:56:23
当控件的创建线程以外的线程尝试访问该控件的某个方法或属性时,通常会导致不可预知的结果。常见的无效线程活动是对访问控件的Handle属性的错误线程的调用
获取或设置一个值,该值指示在调试应用程序时是否捕获访问控件的Handle属性的错误线程上的调用。
看一看
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.checkforillegalcrossthreadcalls.aspx
发布于 2013-08-19 16:52:11
您可以使用Delegate关闭表单
      public delegate void CloseDelagate(); 
      Form1.Invoke(new CloseDelegate(Form2.Close));https://stackoverflow.com/questions/18309785
复制相似问题