[英]Debug.WriteLine locks
My program frequently stops with a deadlock. 我的程序经常因死锁而停止。 When I do a break-all 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 let the program continue the threads are still stuck on that line. 如果我让程序继续,线程仍然停留在该行上。
I can't see where this can lock. 我看不出这可以锁定的地方。 The debug class, string class & datetime class seem to be thread safe. 调试类,字符串类和日期时间类似乎是线程安全的。
The error goes away when I remove the #if DEBUG System... #endif
code but I'm curious why this behavior happens. 当我删除#if DEBUG System... #endif
代码时,错误就消失了,但我很好奇为什么会出现这种情况。
Thread one: 线程一:
public void CleanCache()
{
Logging.WriteClientLog(LogLevel.Debug, "Start clean cache.");//Stuck
}
Thread two: 线程二:
private void AliveThread()
{
Logging.WriteClientLog(LogLevel.Debug, "Check connection");//Stuck
}
Debug.WriteLine writes logging messages to the attached Trace Listeners attached to the Listeners collection. Debug.WriteLine将日志记录消息写入附加到Listeners集合的附加跟踪侦听器 。
One of your trace listeners must have a lock internally which is causing a deadlock. 其中一个跟踪侦听器必须在内部具有锁定,从而导致死锁。 Check your listener code, as it's most likely the culprit. 检查你的听众代码,因为它很可能是罪魁祸首。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.