引用 Knight94(愚翁)的:
----------------------------------------
to 对于多线程,怎么获取特定的线程,每个线程是否有唯一的标识符每个线程有唯一的标识符,如果要想查询当前程序的所有线程,你可以如下:
using System.Diagnostics;Process prcCurrent = Process.GetCurrentProcess();
foreach( Thread thdSubThread in prcCurrent.Threads )
{
//Do what you want here
}
----出现 System.InvalidCastException: 无法将类型为“System.Diagnostics.ProcessThread”的对象强制转换为类型“System.Threading.Thread”。
----------------------------------------
to 对于多线程,怎么获取特定的线程,每个线程是否有唯一的标识符每个线程有唯一的标识符,如果要想查询当前程序的所有线程,你可以如下:
using System.Diagnostics;Process prcCurrent = Process.GetCurrentProcess();
foreach( Thread thdSubThread in prcCurrent.Threads )
{
//Do what you want here
}
----出现 System.InvalidCastException: 无法将类型为“System.Diagnostics.ProcessThread”的对象强制转换为类型“System.Threading.Thread”。
foreach( ProcessThread thdSubThread in prcCurrent.Threads )
{
//Do what you want here
}
foreach( ProcessThread thdSubThread in prcCurrent.Threads )
{
//Do what you want here
}我可以通过上面的方式关闭我的线程吗?
//Do what you want here
该写些什么,
好像不能获得 Thread 再 Aborted()这样的
2)或者尝试用win32 api 来杀线程。
2)或者就是所有线程都检测某个状态并根据状态随时退出。线程还是自行退出最安全,强行杀掉有时候也会有问题。
System.Threading.Thread thread=new System.Threading.Thread()
thread.IsBackground=true;