Stefan Steiger
Stefan Steiger

Reputation: 82186

Global.asax and web application lifetime

Question: When a webapplication gets started, it executes Application_Start in global.asax.

Now, a web application gets started as soon as the first request for a page in that application reaches the server.

But my question is: how long will the application run until the application is stopped. I mean when after the first page request, there's no traffic on the server.

I need to know because I intend to start a server that listens on a tcp port in global.asax. And when the application stops, the server ceases to listen to its port.

Upvotes: 1

Views: 812

Answers (2)

jim tollan
jim tollan

Reputation: 22485

in a word (well 2) - shared hosting.

on shared hosting beware, (godaddy/webhost4life etc) this timeout could well be less, plus you don't have option to configure that on these hosting environments. i've had cases where the app pool is recycled after 5 mins at certain peek times, so you might have to investigate 'wakeup' routines to poke your app to keep in in the memory. i do this for a few shared hosting apps to great effect using pingalive.com.

hope this helps, even if in an abstract way.

jim

Upvotes: 2

Erik van Brakel
Erik van Brakel

Reputation: 23820

It depends on your IIS settings. Your application will run in an application pool, which takes a bunch of settings defining the behaviour of this pool.

The thing you're looking for are recycling settings. In IIS 7, you can access these easily from the management console. Go to Application Pools, right click on the application pool your app runs in (if you don't know which one that is, then it's probably the DefaultAppPool) and select recycling.

Here you'll find the options you have to control the recycling behaviour of your app pool, which in turn controls when your app 'resets'.

Upvotes: 5

Related Questions