我有运行此代码的 .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。问题是当我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
我该如何解决?感谢您的时间和答复。
之所以会出现异常,是因为您试图从线程中而不是在创建窗体时关闭窗体。这是不允许的。
像这样做
this.Invoke((MethodInvoker) delegate
{
// close the form on the forms thread
this.Close();
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句