开发者

How can I track down the thread that is still working after finishing the test?

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 开发者_如何学Pythonthread 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


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.

Menu -> Debug -> Break All

View Threads

The "Threads" window gives you a list of all threads for the current process which is being debugged.

Menu -> Debug -> Windows -> Threads

More detail on the "Threads" window:

http://msdn.microsoft.com/en-us/library/w15yf86f.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜