引用 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”。

解决方案 »

  1.   

    这样得到的确实是ProcessThread实例,有什么问题吗?
      

  2.   

    Process prcCurrent = Process.GetCurrentProcess();
    foreach( ProcessThread thdSubThread in prcCurrent.Threads )
    {
       //Do what you want here
    }
      

  3.   

    Process prcCurrent = Process.GetCurrentProcess();
    foreach( ProcessThread thdSubThread in prcCurrent.Threads )
    {
       //Do what you want here
    }我可以通过上面的方式关闭我的线程吗?
      //Do what you want here
    该写些什么,
     好像不能获得 Thread 再 Aborted()这样的
      

  4.   

    主要是因为我没有关闭线程,就关闭了程序,出现异常,还导致我电脑蓝屏(可能显卡driver装的不好)~~现在通过状态,把所有的线程关闭了 再关闭主线程 程序吧,感觉没什么事了一样
      

  5.   

    1)你自己封装一下线程创建,所有创建走封装接口,这样你就可以控制了。
    2)或者尝试用win32 api 来杀线程。
    2)或者就是所有线程都检测某个状态并根据状态随时退出。线程还是自行退出最安全,强行杀掉有时候也会有问题。
      

  6.   

    把线程设置为后台线程,在程序关闭时就会先等待线程结束在关闭程序
    System.Threading.Thread thread=new System.Threading.Thread()
    thread.IsBackground=true;
      

  7.   

    http://9q.blogspot.com/2006/10/dotnet.html