views:

40

answers:

2

If you start a thread in the Application Start of an asp.net site, what will happen when Application Stop is triggered? Also, the thread I'm starting will run forever.

For instance if there are no active sessions for a while, the application is stopped.

A: 

the global asax have some event where you can manage you code...

if you destroy your objects in the apropieate event...

for Application_Start on Application_End for Session_Start on Session_End

if you thread is one applications variable, will be alive while the application pool is alive...

regards

a52
So, the main thread would simply kill the background thread when the application pool would stop?
Lieven Cardoen
if you are using .net component yes, but, if you are using COM+ may stay on memory...
a52
Well, it's asp.net.
Lieven Cardoen
+1  A: 

Here is a link to Rick Strahl’s blog. He shows two things:

  • How to manage a background thread with an endless loop for the life time of an application. Application_start and Application_end are used.
  • How to keep such a website (and the background thread) alive by restarting the site in Application_end
Dirk
Thx, exactly what I was searching for.
Lieven Cardoen