prevent application shutdown

P

Pint

Is there a way to prevent my web application from shuting down if I
don't have access to machine.config?
Thanks,
Pint
 
B

Brock Allen

If you don't have access to machine.config then this tells me you don't own
the machine (so perhaps you're on a hosted box?). So if you don't own the
machine, then no, there's no way to prevent an admin or anyone else from
walking up to your app and shutting it down.

I suspect the real problem you're having is that the application is getting
automatically recycled. This is a fact of life in ASP.NET and you have to
code to that behavior. There have been a few other threads here recently
on the subject.
 
P

Pint

Does someone know how to prevent application shutdown? Or can you refer
me to the threads that Brock speaks of.
Thanks,
Pint
 
P

Pint

My bad. I will try to more specific when asking this question again. I
already know about google, and already searched for my answer. I found
lots of references there suggesting I also search google. Hmmmm? I
wonder if directing someone to use google when answering a newsgroup
post dilutes the value of google groups.

I have an aspnet application in a hosted environment. My application
spawns threads that do work in the background. That is to say these
threads do not have HttpContext. I keep handles to these threads by
storing them in my Application object.

I do not understand how the application decides to recycle itself. I
would like to keep these threads alive independent of the frequency of
Request to the web server.

It seems a likly hack is to place a webrequest in a timer. It seems
there should be a cleaner way to do this.

Thanks,
Pint
 
B

Brock Allen

Ah, now some specifics... good :)
I do not understand how the application decides to recycle itself. I
would like to keep these threads alive independent of the frequency of
Request to the web server.

Well, when you create managed threads they're scoped to the AppDomain which
is like a process. The AppDomain in ASP.NET essentially maps to the virtual
directory, meaning all page objects, etc for that vdir live in the AppDomain.
The AppDomain settings are initialized from web.config. So, what causes an
AppDomain to get restarted? Well, changes to web.config for one. Also, based
upon machine.config or IIS configuration, the AppDomain can get restarted
based upon the number of requests to the app, the time the app has been running
and many other things...
I have an aspnet application in a hosted environment. My application
spawns threads that do work in the background. That is to say these
threads do not have HttpContext. I keep handles to these threads by
storing them in my Application object.

So this is cool, it's just that you need to manage this appropriately. I'd
suggest not using the Application object to store this data. Instead use
static (C#) or Shared (VB.NET) data structures to store this data. It's essentially
the same and you don't rely upon a HttpContext for the storage. The big thing
is to clean up these resources when the AppDomain is shutting down. You can
handle the AppDomain.DomainUnload event. Very much the same idea as Application_End,
but again it's not tied to the ASP.NET plumbing. This is where you can do
the cleanup of those handles that you're storeing in static variables.

HTH (and it's 100% google free :p)
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top