积极答复者
c# 怎么查找是否存在某个线程

问题
-
答案
-
- 已标记为答案 CaillenModerator 2014年1月15日 3:10
-
hello
可以使用線程視窗
http://www.dotblogs.com.tw/yc421206/archive/2011/01/17/20864.aspx
http://msdn.microsoft.com/zh-cn/library/w15yf86f.aspx或Parallel Stacks 視窗
http://www.dotblogs.com.tw/yc421206/archive/2013/05/16/104260.aspx
秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/
- 已标记为答案 CaillenModerator 2014年1月15日 3:10
全部回复
-
- 已标记为答案 CaillenModerator 2014年1月15日 3:10
-
hello
可以使用線程視窗
http://www.dotblogs.com.tw/yc421206/archive/2011/01/17/20864.aspx
http://msdn.microsoft.com/zh-cn/library/w15yf86f.aspx或Parallel Stacks 視窗
http://www.dotblogs.com.tw/yc421206/archive/2013/05/16/104260.aspx
秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/
- 已标记为答案 CaillenModerator 2014年1月15日 3:10
-
你好:
你可以检查Thread.IsAlive属性来判断一个线程是否在执行状态,具体的线程状态可以查看ThreadState属性。
如果想跟踪自己创建的所有线程,那么可以创建一个自定义的线程池,比如如下:
public class MyThreadPool { private IList<Thread> _threads; private readonly int MAX_THREADS = 25; public MyThreadPool() { _threads = new List<Thread>(); } public void LaunchThreads() { for (int i = 0; i < MAX_THREADS;i++) { Thread thread = new Thread(ThreadEntry); thread.IsBackground = true; thread.Name = string.Format("MyThread{0}",i); _threads.Add(thread); thread.Start(); } } public void KillThread(int index) { string id = string.Format("MyThread{0}",index); foreach (Thread thread in _threads) { if (thread.Name == id) thread.Abort(); } } void ThreadEntry() { } }
通过遍历集合中的线程名称来获取到想要的线程,然后判断线程的状态。We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.