System.Threading.ThreadAbortException: Thread was being aborted.

  • Thread starter Daniel Knöpfel
  • Start date
D

Daniel Knöpfel

Hi

I am develloping an asp.net 2.0 application. For some tasks (daily
notifications to users via email), we use background threads. I rather have
this task as background thread of the asp.net application and not as a
service as as the installation procedure of a service on the productive
system would cause a lot of administrative overhead.

The thread is started in the global.asax file on startup. Strangely, after
some time, the thread is being aborted with a ThreadAbortException,
(Message: Thread was being aborted) I do not see a logical reason for this.
Does asp.net or iis prevent prevent threads running in the background for a
long time? If yes, how can i change this? This is really crucial for the
task, that must be performed.

Thanks in advance for any help

Daniel














PS: code snippet on how the thread is started
public static void Application_Start(object sender, EventArgs e) {

notificationThread = new Thread(new ThreadStart(StartNotificationThread));

notificationThread.IsBackground = true;

notificationThread.Priority = ThreadPriority.Lowest;

notificationThread.Start();
 
D

Damien

Daniel said:
Hi

I am develloping an asp.net 2.0 application. For some tasks (daily
notifications to users via email), we use background threads. I rather have
this task as background thread of the asp.net application and not as a
service as as the installation procedure of a service on the productive
system would cause a lot of administrative overhead.

The thread is started in the global.asax file on startup. Strangely, after
some time, the thread is being aborted with a ThreadAbortException,
(Message: Thread was being aborted) I do not see a logical reason for this.
Does asp.net or iis prevent prevent threads running in the background for a
long time? If yes, how can i change this? This is really crucial for the
task, that must be performed.
Is the worker process being recycled? This is a "normal" aspect of life
for an asp.net application, and one of the reasons normally stated for
using a service rather than asp.net threads for background tasks.
However, you've indicated that you don't want to go down that route, so
I'll save the rest of the speech.

I don't believe we've played with these settings on our server, so I
believe I'm looking at the defaults, that the worker process is
automatically recycled every 29 hours, and that the worker process will
be shut down after 20 minutes of inactivity. So unless you change these
settings, the process your thread is living in will be torn down during
quiet times on the server.

Damien
 
D

Daniel Knöpfel

Hi Damien

Thanks for your answer. Yes the worker process is recycled. However, i
believe the thead is aborted before the thread is actually recycled.
Furthermore, in case of recycling the global.asax startup event would be
raised and the worker process would be running again, which would be ok the
way we had it implemented. What might has an influence is the fact that the
thread is a background thread (if application is shut down (e.g. iisreset)
the thread should stop as well and that the thread is put to sleep for a
long time.


I will also deeper look at the recycling issue.

Thanks for your help Damien

Greetings

Daniel


e.g: Code snippets:

Thread start:
notificationThread = new Thread(new ThreadStart(StartNotificationThread));
notificationThread.Name = uniqueThreadName;

notificationThread.IsBackground = true;

notificationThread.Priority = ThreadPriority.Lowest;

notificationThread.Start();


Thread put to sleep:

Thread.Sleep(800000); // wait a long time and then try again!!




Daniel said:
Hi

I am develloping an asp.net 2.0 application. For some tasks (daily
notifications to users via email), we use background threads. I rather
have
this task as background thread of the asp.net application and not as a
service as as the installation procedure of a service on the productive
system would cause a lot of administrative overhead.

The thread is started in the global.asax file on startup. Strangely, after
some time, the thread is being aborted with a ThreadAbortException,
(Message: Thread was being aborted) I do not see a logical reason for
this.
Does asp.net or iis prevent prevent threads running in the background for
a
long time? If yes, how can i change this? This is really crucial for the
task, that must be performed.
Is the worker process being recycled? This is a "normal" aspect of life
for an asp.net application, and one of the reasons normally stated for
using a service rather than asp.net threads for background tasks.
However, you've indicated that you don't want to go down that route, so
I'll save the rest of the speech.

I don't believe we've played with these settings on our server, so I
believe I'm looking at the defaults, that the worker process is
automatically recycled every 29 hours, and that the worker process will
be shut down after 20 minutes of inactivity. So unless you change these
settings, the process your thread is living in will be torn down during
quiet times on the server.

Damien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top