简体   繁体   English

有没有办法在 Visual Studio 中以单线程模式调试多线程应用程序?

[英]Is there a way to debug multithreaded applications in singletreaded mode in Visual Studio?

When I debug multithreaded .net applications I want the max degree of parallelism to be 1. I mean I want only one thread to run at a time.当我调试多线程 .net 应用程序时,我希望最大并行度为 1。我的意思是我希望一次只运行一个线程。

In that way I wouldn't have to go through long tutorials about flagging threads, using parallel watch or learn how find out the ID of "my thread".这样,我就不必通过有关标记线程的长教程、使用并行监视或学习如何找出“我的线程”的 ID 来 go。 All I am interested in is to debug multithreaded application in a singletreaded mode.我感兴趣的只是在单线程模式下调试多线程应用程序。

Is there any way of making Visual Studio work with one thread at a time?有什么方法可以让 Visual Studio 一次使用一个线程? Or make my .net application single threaded with a global setting?或者使我的 .net 应用程序具有全局设置单线程? Or a workaround, maybe set Windows 10 to run in singlethreaded mode?或者一种解决方法,也许将 Windows 10 设置为在单线程模式下运行? Be creative!要有创意!

Is there a way to debug multithreaded applications in singletreaded mode in Visual Studio?有没有办法在 Visual Studio 中以单线程模式调试多线程应用程序?

Just as Dialecticus suggested, you could try these:正如Dialecticus建议的那样,您可以尝试以下方法:

Suggestion建议

1) Use Threads Window 1)使用线程 Window

  • first, set a breakpoint at the entry of the main function首先,在主function的入口处设置断点

  • start debugging and then enter Debug --> Windows --> Threads --> then right-click on the threads that you do not want to debug and then select Freeze .开始调试,然后输入Debug --> Windows --> Threads --> 然后右键单击不想调试的线程然后 select Freeze And note that you have to always click on switch to thread , every time something happens.请注意,每次发生某些事情时,您都必须始终单击switch to thread

  • You can refer to this document about using Threads Window.你可以参考这篇关于使用线程 Window 的文档

2) you can try to follow this document to set a new breakpoint about the specific single thread ID to debug it. 2)您可以尝试按照这个文档设置一个关于特定单线程ID的新断点来调试它。

3) there is also a vs extension called Debug Single Thread . 3)还有一个叫做Debug Single Thread的 vs 扩展。 You can also use it.你也可以使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM