完成测试后如何找到仍在工作的线程?

发布于 2024-10-14 10:25:20 字数 1074 浏览 1 评论 0原文

我正在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人事已非 2024-10-21 10:25:20

如果 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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文