【发布时间】:2019-03-22 21:55:49
【问题描述】:
从 VS 运行代码后,我们有一个包含多个项目的解决方案,通常从 Debug.Writeline 语句中看到的输出不再出现。我提到了多个项目,因为其中一个项目的输出继续出现。但是,另一个项目始终停止显示语句的输出。
它开始让我发疯。我应该提到这也发生在该项目的第二个开发人员身上。有人见过这个,或者有什么想法吗?
【问题讨论】:
从 VS 运行代码后,我们有一个包含多个项目的解决方案,通常从 Debug.Writeline 语句中看到的输出不再出现。我提到了多个项目,因为其中一个项目的输出继续出现。但是,另一个项目始终停止显示语句的输出。
它开始让我发疯。我应该提到这也发生在该项目的第二个开发人员身上。有人见过这个,或者有什么想法吗?
【问题讨论】:
在被此折磨多年后,我终于在这个 Stack Overflow 问题中找到了原因和解决方案:vs2010 Debug.WriteLine stops working
Visual Studio 对 debug.writeline 的处理似乎无法处理每个都正确使用多个线程的多个进程。最终,这两个进程将导致处理输出的部分 Visual Studio 死锁,导致其停止工作。
解决方案是将您对 debug.writeline 的调用封装在一个类中,该类使用命名的互斥锁跨进程同步。这可以防止多个进程同时写入进行调试,从而很好地解决了整个死锁问题。
包装器:
public class Debug
{
#if DEBUG
private static readonly Mutex DebugMutex =new Mutex(false,@"Global\DebugMutex");
#endif
[Conditional("DEBUG")]
public static void WriteLine(string message)
{
DebugMutex.WaitOne();
System.Diagnostics.Debug.WriteLine(message);
DebugMutex.ReleaseMutex();
}
[Conditional("DEBUG")]
public static void WriteLine(string message, string category)
{
DebugMutex.WaitOne();
System.Diagnostics.Debug.WriteLine(message,category);
DebugMutex.ReleaseMutex();
}
}
或者对于那些使用 VB.NET 的人:
Imports System.Threading
Public Class Debug
#If DEBUG Then
Private Shared ReadOnly DebugMutex As New Mutex(False, "Global\DebugMutex")
#End If
<Conditional("DEBUG")> _
Public Shared Sub WriteLine(message As String)
DebugMutex.WaitOne()
System.Diagnostics.Debug.WriteLine(message)
DebugMutex.ReleaseMutex()
End Sub
<Conditional("DEBUG")> _
Public Shared Sub WriteLine(message As String, category As String)
DebugMutex.WaitOne()
System.Diagnostics.Debug.WriteLine(message, category)
DebugMutex.ReleaseMutex()
End Sub
End Class
【讨论】:
按照这些步骤,它对我有用
希望对你有帮助
【讨论】:
您应该尝试 Microsoft SystemInternals 的 DebugView。
http://technet.microsoft.com/en-us/sysinternals/bb896647
问候, 艾伦
【讨论】:
尝试检查解决方案的平台是否设置为任何 CPU 而不是 x86(或 x64)。我使用 x86 启用 Edit and Continue,然后丢失了 Debug 输出。回到 AnyCPU 后,输出也回来了。
【讨论】:
我在使用 Visual Studio 2010 时遇到了同样的问题。上述解决方案都不适用于我的情况,但我是这样解决的:
不知道它的确切用途,但现在我的Debug.Print 语句再次出现在即时窗口中,我终于可以重新开始工作了。
【讨论】:
在 VS 2015 中得到了这个。突然间所有 Debug.WriteLine “停止工作”(未显示在输出窗口中)。在为此疯狂了大约一个小时后,我发现了问题: 1.右键单击In output window(从Debug输出) 2.检查“程序输出”是否被选中
【讨论】: