ThreadAbortException occured when call lock()
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 XXXSynchronizedQueue.cs:line 71 at
XXX.SynchronizedQueue.waitForNextContent() in
XXXSynchronizedQueue.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.
c# asp.net
add a comment |
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 XXXSynchronizedQueue.cs:line 71 at
XXX.SynchronizedQueue.waitForNextContent() in
XXXSynchronizedQueue.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.
c# asp.net
Possible duplicate of Why am i getting "Thread was being aborted" in asp.net?
– 500 - Internal Server Error
Nov 22 at 16:36
1
That's not caused bylock
. It occurs because the application or the thread is getting terminated. If the thread is blocked bylock
, that's where the abort will surface. Is this a long-running background thread in a Web application perhaps? In this case the application never worked reliably. It was only a matter of time until that background thread got killed for any number of reasons. Check How to run Background Tasks in ASP.NET
– Panagiotis Kanavos
Nov 22 at 16:36
@PanagiotisKanavos, it is a long-running app hosted in IIS. Although the way I am running it is not reliable, I should be able to make it work at least. But now I keeps throwing exception. Why?
– Yuanfei Bi
Nov 22 at 17:13
1
@YuanfeiBi because it's not reliable. The linked article explains why - if ASP.NET and IIS don't know about background threads and tasks, eventually they kill them. An application pool will be recycled periodically, also killing any threads. If such a background thread throws, it terminates the app pool. The article explains how to use background tasks properly
– Panagiotis Kanavos
Nov 22 at 17:21
Locking and long running app on IIS are both bad ideas. That’s why you can find tons of posts on SO. Try to move them out to another proper application (like Windows service) and use lock free approaches in the long term.
– Lex Li
Nov 23 at 0:19
add a comment |
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 XXXSynchronizedQueue.cs:line 71 at
XXX.SynchronizedQueue.waitForNextContent() in
XXXSynchronizedQueue.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.
c# asp.net
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 XXXSynchronizedQueue.cs:line 71 at
XXX.SynchronizedQueue.waitForNextContent() in
XXXSynchronizedQueue.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.
c# asp.net
c# asp.net
edited Nov 22 at 16:41
Panagiotis Kanavos
53.4k479107
53.4k479107
asked Nov 22 at 16:30
Yuanfei Bi
265
265
Possible duplicate of Why am i getting "Thread was being aborted" in asp.net?
– 500 - Internal Server Error
Nov 22 at 16:36
1
That's not caused bylock
. It occurs because the application or the thread is getting terminated. If the thread is blocked bylock
, that's where the abort will surface. Is this a long-running background thread in a Web application perhaps? In this case the application never worked reliably. It was only a matter of time until that background thread got killed for any number of reasons. Check How to run Background Tasks in ASP.NET
– Panagiotis Kanavos
Nov 22 at 16:36
@PanagiotisKanavos, it is a long-running app hosted in IIS. Although the way I am running it is not reliable, I should be able to make it work at least. But now I keeps throwing exception. Why?
– Yuanfei Bi
Nov 22 at 17:13
1
@YuanfeiBi because it's not reliable. The linked article explains why - if ASP.NET and IIS don't know about background threads and tasks, eventually they kill them. An application pool will be recycled periodically, also killing any threads. If such a background thread throws, it terminates the app pool. The article explains how to use background tasks properly
– Panagiotis Kanavos
Nov 22 at 17:21
Locking and long running app on IIS are both bad ideas. That’s why you can find tons of posts on SO. Try to move them out to another proper application (like Windows service) and use lock free approaches in the long term.
– Lex Li
Nov 23 at 0:19
add a comment |
Possible duplicate of Why am i getting "Thread was being aborted" in asp.net?
– 500 - Internal Server Error
Nov 22 at 16:36
1
That's not caused bylock
. It occurs because the application or the thread is getting terminated. If the thread is blocked bylock
, that's where the abort will surface. Is this a long-running background thread in a Web application perhaps? In this case the application never worked reliably. It was only a matter of time until that background thread got killed for any number of reasons. Check How to run Background Tasks in ASP.NET
– Panagiotis Kanavos
Nov 22 at 16:36
@PanagiotisKanavos, it is a long-running app hosted in IIS. Although the way I am running it is not reliable, I should be able to make it work at least. But now I keeps throwing exception. Why?
– Yuanfei Bi
Nov 22 at 17:13
1
@YuanfeiBi because it's not reliable. The linked article explains why - if ASP.NET and IIS don't know about background threads and tasks, eventually they kill them. An application pool will be recycled periodically, also killing any threads. If such a background thread throws, it terminates the app pool. The article explains how to use background tasks properly
– Panagiotis Kanavos
Nov 22 at 17:21
Locking and long running app on IIS are both bad ideas. That’s why you can find tons of posts on SO. Try to move them out to another proper application (like Windows service) and use lock free approaches in the long term.
– Lex Li
Nov 23 at 0:19
Possible duplicate of Why am i getting "Thread was being aborted" in asp.net?
– 500 - Internal Server Error
Nov 22 at 16:36
Possible duplicate of Why am i getting "Thread was being aborted" in asp.net?
– 500 - Internal Server Error
Nov 22 at 16:36
1
1
That's not caused by
lock
. It occurs because the application or the thread is getting terminated. If the thread is blocked by lock
, that's where the abort will surface. Is this a long-running background thread in a Web application perhaps? In this case the application never worked reliably. It was only a matter of time until that background thread got killed for any number of reasons. Check How to run Background Tasks in ASP.NET– Panagiotis Kanavos
Nov 22 at 16:36
That's not caused by
lock
. It occurs because the application or the thread is getting terminated. If the thread is blocked by lock
, that's where the abort will surface. Is this a long-running background thread in a Web application perhaps? In this case the application never worked reliably. It was only a matter of time until that background thread got killed for any number of reasons. Check How to run Background Tasks in ASP.NET– Panagiotis Kanavos
Nov 22 at 16:36
@PanagiotisKanavos, it is a long-running app hosted in IIS. Although the way I am running it is not reliable, I should be able to make it work at least. But now I keeps throwing exception. Why?
– Yuanfei Bi
Nov 22 at 17:13
@PanagiotisKanavos, it is a long-running app hosted in IIS. Although the way I am running it is not reliable, I should be able to make it work at least. But now I keeps throwing exception. Why?
– Yuanfei Bi
Nov 22 at 17:13
1
1
@YuanfeiBi because it's not reliable. The linked article explains why - if ASP.NET and IIS don't know about background threads and tasks, eventually they kill them. An application pool will be recycled periodically, also killing any threads. If such a background thread throws, it terminates the app pool. The article explains how to use background tasks properly
– Panagiotis Kanavos
Nov 22 at 17:21
@YuanfeiBi because it's not reliable. The linked article explains why - if ASP.NET and IIS don't know about background threads and tasks, eventually they kill them. An application pool will be recycled periodically, also killing any threads. If such a background thread throws, it terminates the app pool. The article explains how to use background tasks properly
– Panagiotis Kanavos
Nov 22 at 17:21
Locking and long running app on IIS are both bad ideas. That’s why you can find tons of posts on SO. Try to move them out to another proper application (like Windows service) and use lock free approaches in the long term.
– Lex Li
Nov 23 at 0:19
Locking and long running app on IIS are both bad ideas. That’s why you can find tons of posts on SO. Try to move them out to another proper application (like Windows service) and use lock free approaches in the long term.
– Lex Li
Nov 23 at 0:19
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435042%2fthreadabortexception-occured-when-call-lock%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435042%2fthreadabortexception-occured-when-call-lock%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Why am i getting "Thread was being aborted" in asp.net?
– 500 - Internal Server Error
Nov 22 at 16:36
1
That's not caused by
lock
. It occurs because the application or the thread is getting terminated. If the thread is blocked bylock
, that's where the abort will surface. Is this a long-running background thread in a Web application perhaps? In this case the application never worked reliably. It was only a matter of time until that background thread got killed for any number of reasons. Check How to run Background Tasks in ASP.NET– Panagiotis Kanavos
Nov 22 at 16:36
@PanagiotisKanavos, it is a long-running app hosted in IIS. Although the way I am running it is not reliable, I should be able to make it work at least. But now I keeps throwing exception. Why?
– Yuanfei Bi
Nov 22 at 17:13
1
@YuanfeiBi because it's not reliable. The linked article explains why - if ASP.NET and IIS don't know about background threads and tasks, eventually they kill them. An application pool will be recycled periodically, also killing any threads. If such a background thread throws, it terminates the app pool. The article explains how to use background tasks properly
– Panagiotis Kanavos
Nov 22 at 17:21
Locking and long running app on IIS are both bad ideas. That’s why you can find tons of posts on SO. Try to move them out to another proper application (like Windows service) and use lock free approaches in the long term.
– Lex Li
Nov 23 at 0:19