C# Abort()ing threads on exit for a Form
Posted
by Gio Borje
on Stack Overflow
See other posts from Stack Overflow
or by Gio Borje
Published on 2010-04-24T17:09:18Z
Indexed on
2010/04/24
17:13 UTC
Read the original article
Hit count: 291
So far I have this code run when the X button is clicked, but I'm not sure if this is the correct way to terminate threads on a form on exit.
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[] {});
}
}
I keep getting this error: "An attempt has been made to free an RCW that is in use. The RCW is in use on the active thread or another thread. Attempting to free an in-use RCW can cause corruption or data loss."
© Stack Overflow or respective owner