Visual Studio - C# 错误:System.Windows.Forms.dll 中发生类型为“System
本文关键字:System 类型 dll Windows Studio 错误 Visual Forms | 更新日期: 2023-09-27 17:57:20
每次
调试程序并尝试关闭程序然后程序关闭时,我都会收到错误,并且我收到此错误An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
并向我展示我在代码中有一些错误。
我的代码:
void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (stop)
{
var proc = (Process)sender;
stop = false; // allows you to spawn a new thread after stopping the first
proc.SynchronizingObject = this; // puts the form in charge of async communication
proc.Kill(); // terminates the thread
proc.WaitForExit(); // thread is killed asynchronously, so this goes here...
}
if (e.Data != null)
{
string newLine = e.Data.Trim() + Environment.NewLine;
MethodInvoker append = () => {
pingInformatsioon.Text += newLine;
if (checkBox1.Checked)
{
WriteLog(newLine);
}
};
pingInformatsioon.BeginInvoke(append);
}
}
总是出现黄色pingInformatsioon.BeginInvoke(append);
好像有什么不对劲..
您可能从 UI 线程以外的线程调用此代码。尝试替换
pingInformatsioon.BeginInvoke(append);
用这样的东西
if (InvokeRequired)
pingInformatsioon.BeginInvoke(append);
else
Invoke(append);