到目前为止,我在单击 X 按钮时运行了此代码,但我不确定这是否是在退出时终止窗体上的线程的正确方法。
Type t = this.GetType();
foreach (PropertyInfo pi in t.GetProperties())
{
if (pi.GetType() == typeof(Thread))
{
MethodInfo mi = pi.GetType().GetMethod("Abort");
mi.Invoke(null, new object[] {});
}
}
我不断收到此错误:“已尝试释放正在使用的 RCW。RCW 正在活动线程或其他线程上使用。尝试释放正在使用的 RCW 可能会导致损坏或数据丢失。”