Debug.WriteLine Lock

My program often stops with a dead end. When I take a break and look at the threads, I see that three threads are stuck in our logging function:

public class Logging { public static void WriteClientLog(LogLevel logLevel, string message) { #if DEBUG System.Diagnostics.Debug.WriteLine(String.Format("{0} {1}", DateTime.Now.ToString("HH:mm:ss"), message)); //LOCK #endif //...Log4net logging } } 

If I allow the program to continue, the threads still remain on this line.

I do not see where this can be blocked. The debug class, string class, and datetime class seem thread safe.

The error is removed when I delete the #if DEBUG System... #endif code, but I'm curious why this happens.

Insert one:

 public void CleanCache() { Logging.WriteClientLog(LogLevel.Debug, "Start clean cache.");//Stuck } 

Stream two:

 private void AliveThread() { Logging.WriteClientLog(LogLevel.Debug, "Check connection");//Stuck } 
+4
source share
1 answer

Debug.WriteLine writes registration messages to attached trace listeners attached to Listeners .

One of your trace listeners must have an internal lock that causes a deadlock. Check your listener code as it is most likely the culprit.

+4
source

Source: https://habr.com/ru/post/1308675/


All Articles