完成测试后如何找到仍在工作的线程?
我正在将 NUnit 与 Resharper 一起使用。当我完成一项测试时,JetBrain:Resharper 进程仍在工作,当我写出其线程时,仍有一些线程在工作。我可以查出它是什么类型的线程吗?我目前正在使用以下代码,但它只提供了线程 ID。我需要线程名称。
Process[] allProcs = Process.GetProcesses();
foreach (Process proc in allProcs)
{
if (proc.ProcessName.StartsWith("Jet"))
{
ProcessThreadCollection myThreads = proc.Threads;
Console.WriteLine("process: {0}, id: {1}", proc.ProcessName, proc.Id);
foreach (ProcessThread pt in myThreads)
{
Console.WriteLine(" thread: {0}", pt.Id);
Console.WriteLine(" started: {0}", pt.StartTime.ToString());
Console.WriteLine(" CPU time: {0}", pt.TotalProcessorTime);
Console.WriteLine(" priority: {0}", pt.BasePriority);
Console.WriteLine(" thread state: {0}", pt.ThreadState.ToString());
}
}
}
上面代码的输出:
process: JetBrains.ReSharper.TaskRunner.MSIL, id: 1884
thread: 3600
started: 27.1.2011 13.26.55
CPU time: 00:00:05.8812377
priority: 8
thread state: Running
I am using NUnit with Resharper. When I finish one test, the JetBrain:Resharper process is still working and when I write out its threads, there is still some thread working. Can I track down what kind of thread it is? I am currently using the following code, but it only gives me the thread ID. I need the thread name.
Process[] allProcs = Process.GetProcesses();
foreach (Process proc in allProcs)
{
if (proc.ProcessName.StartsWith("Jet"))
{
ProcessThreadCollection myThreads = proc.Threads;
Console.WriteLine("process: {0}, id: {1}", proc.ProcessName, proc.Id);
foreach (ProcessThread pt in myThreads)
{
Console.WriteLine(" thread: {0}", pt.Id);
Console.WriteLine(" started: {0}", pt.StartTime.ToString());
Console.WriteLine(" CPU time: {0}", pt.TotalProcessorTime);
Console.WriteLine(" priority: {0}", pt.BasePriority);
Console.WriteLine(" thread state: {0}", pt.ThreadState.ToString());
}
}
}
Output from code above:
process: JetBrains.ReSharper.TaskRunner.MSIL, id: 1884
thread: 3600
started: 27.1.2011 13.26.55
CPU time: 00:00:05.8812377
priority: 8
thread state: Running
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 ReSharper 测试运行程序进程仍然存在,则将调试器附加到它并“中断所有”以查看当前正在执行的线程。
将 Visual Studio 调试器附加到进程
下面演示如何将 VS 调试器附加到正在运行的进程。选择要附加的进程时也选择 ReSharper 测试运行程序。
http://msdn.microsoft.com/en-us/library/c6wf8e4z.aspx
全部中断
选择此选项将挂起所有正在运行的线程并允许您检查它们。
查看线程
“线程”窗口为您提供当前正在调试的进程的所有线程的列表。
有关“线程”窗口的更多详细信息:
http://msdn.microsoft.com /en-us/library/w15yf86f.aspx
If the ReSharper test runner process is still there then attach the debugger to it and "break all" to see the currently executing threads.
Attach Visual Studio debugger to process
The following shows how to attach the VS debugger to a running process. Choose the ReSharper test runner when choosing which process to attach too.
http://msdn.microsoft.com/en-us/library/c6wf8e4z.aspx
Break All
Choosing this option will suspend all running threads and allow you to inspect them.
View Threads
The "Threads" window gives you a list of all threads for the current process which is being debugged.
More detail on the "Threads" window:
http://msdn.microsoft.com/en-us/library/w15yf86f.aspx