Why does Debug.Writeline stop working for some projects in the solution?

后端 未结 6 1631
广开言路
广开言路 2020-12-04 00:21

We have a solution with multiple projects after running the code from VS the output normally seen from Debug.Writeline statements just cease to appear. I mention the multip

相关标签:
6条回答
  • 2020-12-04 00:32

    Try checking if Platform for the solution is set to Any CPU and not x86 (or x64). I used x86 to enable Edit and Continue and then lost Debug output. After going back to AnyCPU the Output is also back.

    0 讨论(0)
  • 2020-12-04 00:37

    After being tormented by this for years I finally found the cause and the solution in this Stack Overflow question: vs2010 Debug.WriteLine stops working

    It seems that Visual Studio's handinlg of debug.writeline can't handle multiple processeses that each use multiple threads correctly. Eventually the 2 processes will deadlock the portion of visual studio that handles the output, causing it to stop working.

    The solution is to wrap your calls to debug.writeline in a class that synchronizes across processes using a named mutex. This prevents multiple processes from writing to debug at the same time, nicely side stepping the whole deadlock problem.

    The wrapper:

    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();
         }
    }
    

    Or for those using 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
    
    0 讨论(0)
  • 2020-12-04 00:37

    you should try DebugView from Microsoft SystemInternals.

    http://technet.microsoft.com/en-us/sysinternals/bb896647

    Regards, Allen

    0 讨论(0)
  • 2020-12-04 00:38

    I had the same problem with Visual Studio 2010. None of the above solutions worked in my case, but I solved it like this:

    1. Right-click on your project.
    2. Select Properties.
    3. Click the Compile tab.
    4. Scroll down to "Advanced Compile Options".
    5. Change the value for "Generate debug info" from "pdb-only" to "Full".

    No idea what it's for exactly, but now my Debug.Print statements appear in the Immediate Window again I can finally get back to work.

    0 讨论(0)
  • 2020-12-04 00:52

    Follow these steps, it works for me

    1. Right click on your project
    2. Select Properties
    3. Select tab Build
    4. Make sure Define DEBUG constant is checked

    Hope that helps

    0 讨论(0)
  • 2020-12-04 00:56

    Got this in VS 2015. All of a sudden all Debug.WriteLine "stops working" (not showing in Output window). After going crazy about this for about an hour I found the problem: 1. Right click In output window (output from Debug) 2. Check that "Program output" is checked

    0 讨论(0)
提交回复
热议问题