I have an C# app which works fine for a long time. But suddenly it starts throw ThreadAbortException
. The error message is that:
Error when logging System.Threading.ThreadAbortException: Thread was being aborted. at System.Threading.Monitor.Enter(Object obj) at XXX.getLogContent() in XXX\SynchronizedQueue.cs:line 71 at XXX.SynchronizedQueue.waitForNextContent() in XXX\SynchronizedQueue.cs:line 51 at XXX.ThreadLogger.logThreadDB() in XXX.ThreadLogger.cs:line 97
At first I thought it is IIS issue, we have reset the recycle pool, but it does not help. And there is sufficient disk space for log. The code (line 51 and 71 is marked) is:
public Queue<LogContent> waitForNextContent()
{
Queue<LogContent> lCurrentLogContent;
while (true)
{
lCurrentLogContent = getLogContent(); # line 51
if (lCurrentLogContent.Count == 0)
{
//wait
lock (mThreadMonitorLock)
{
Monitor.Wait(mThreadMonitorLock);
}
}
else
{
break;
}
}
return lCurrentLogContent;
}
private Queue<LogContent> getLogContent()
{
Queue<LogContent> lLogContent = new Queue<LogContent>();
lock (mQueueLock) # line 71
{
while (mLogContentQueue.Count > 0)
{
lLogContent.Enqueue(mLogContentQueue.Dequeue());
}
}
return lLogContent;
}
It seems it is related to C# lock(). But why it works fine in the past? Any help is greatly appreciated. Thanks.