asp.net thread cleanup

G

Guest

I currently have an asp.net web app that starts a thread in the global.asax
app start method. THe thread then runs for the duration of the app's life,
changing data in the background.

My question is what cleanup do i have to do for the thread when the app is
stopped? Do i need to do anything at all? Should I put a threadname.abort in
the application_end? I wasn't sure what cleanup to do.

Thanks.
 
V

Vadym Stetsyak

Your thread operates under some condition, right?
On each loop cycle this condition is begin checked, and if it is true thread
loop continues ( thread is going on )
and if not - loop is exited ( thread shutdowns ).

You can make this condition "visible" for the whole class that is you can
specify this condition in
application_end routine to false and thread will "naturally" exit.

About cleanup it depends what actions are performed in the thread, that is
if you use some unmanaged resources ( db connections, socket connections,
interop etc ) you have to either call Dispose or Close, or Shutdown. It
depends on the type of resources your thread is using.
 
G

Guest

Thanks for the info. My thread is working exactly like you said. Is there
still anything that has to be done for the thread itself. Like calling
thread.abort in the loop (if it doesn't continue)? Thanks again for your help.
 

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

Top