intercept shutdown of a IIS garden process to terminate a bkgd thr

G

Guest

I have a ASP.NET webservice and it is configured to run in a web garden with
multiple processes.

Whan a process in the garden is launched, I want the process to create a
background thread. When request are received by this instance of the garden
process, a meessage is posted to the background thread to do its work. When
the garden process is being down by IIS (due to a period of inactivity), I
want to notify the background thread to gracefully terminate.

I create and launch the background thread when a method is the webservice is
first invoked. How do I intercept the shutdown event for the garden process
to terminate the background thread?

According to MSDN documentation, Application_End is not the place to do it
because it is called when the ASP.NET application is shutdown and not
instances of the garden process.

Thanks.
 
S

Steven Cheng[MSFT]

Welcome to the ASP.NET newsgroup.

From your description, I understand you've developed an ASP.NET webservice,
the service will launch a background thread for task processing. Also,
you're curently configuring the webservice application as webgarden mode in
IIS, so you're wondering what's the proper place to intercept the startup
and shutdown of the IIS webgarden process so that you can gracefully
clearup the background thread, correct? If anything I didn't quite get,
please feel free to let me know.

Based on my understanding, for ASP.NET webservice application, it is the
same with the ASP.NET web page based application, the Application_Start,
and Application_End events are the two ones we can use to do some startup
and shutdown tasks. And for IIS worker process, there is not interfaces for
us to intercepting its startup and shutdown in managed code.

Actually, the Application_End and Application_Start events are the
reasonable ones for your scenario, because these two events are specific to
ASP.NET application's runtime appdomain(AppDomain's startup and AppDomain's
teardown). So when we're creating background threads in our asp.net
application, the thread(managed thread) is associated with its host
AppDomain, so when the application restart, the background thread will also
be disposed, so it's reasonable to put the clearup code in Application_End
event.

In addition, for IIS6, there provides the application pool process
isolation model, we can create a particular application pool for our
webservice application. Thus, each webgarden worker process is associated
with that particular application pool and the worker process will contains
only our web service appliation's AppDomain, this can help isolated our
application from other web application well.

Hope this helps some. Please feel free to post here if you have any other
consideration.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Steven,

Thanks for the reply. Your understanding of my question is correct.

You recommend that the cleanup be done at Application_End. However,
according to MSDN documentation, it indicates that Application_End is
exeucted for the ASP.NET application when it shuts down and it is not called
during each garden instance being shutdown.

Did I misread the MSDN documentation? Thanks.
 
S

Steven Cheng[MSFT]

Thanks for your response,

Your understanding on the "Application_End" event is correct, it is
exeucted for the ASP.NET application when it shuts down. Actually so far we
haven't any built-in .net events or interface to intercepting IIS worker
process's shutdown or recycle. However, when IIS worker process( the
webgarden process shutss down, the application will certainly be shutdown
first, so this event will be triggered too).

Also, as I mentioned in the former message, ASP.NET managed threads are
associated with appdomain, and ASP.NET application instance is just an
AppDomain, so when the application restart or shutdown, those managed
threads associated with this appdomain will also be destroyed. Therefore I
think the Application_End event is appropriate for doing cleanup for your
background thread. How do you think?

In addition, for your webgarden scenairo, each worker process(in your ase
there will have at most 3 ones) will contains an appDomain for your ASP.NET
application, and when any of them(Appdomain) are restarted, or shutdown,
the Application_End event will fire for that certain AppDomain.

Hope this makes it clear. If there is still anything I missed, or anything
we can help, please feel free to let me know.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Glad to be of assistance.

If you meet any new problem or anything else we can help, please feel free
to post here.

Good luck!

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top