tags:

views:

394

answers:

4

I have windows task which restarts IIS at midnight 00:00. In my application there is a background thread which runs a global refresh at around 02:00.

My problem is that the application starts only on the first request from a browser. This may not occur for quite some time and the global refresh can be late in starting.

Is there any way to start the application without first browsing to the web application?

+3  A: 

You can have another task that accesses your web site after IIS is restarted.

Still, I can't see why would you have a thread doing maintenance inside your IIS worker process. If the process dies from some reason (for example - because of the recycling configuration in the web site's application pool) the work won't get done. It's better to do this from a separate process, such as windows service or a scheduled windows task.

Doron Yaacoby
+1  A: 

You shouldn't have any threads scheduled inside an IIS web application - becasue IIS has some logic to recycle the worker process and your application when it is not used. Its better to run it as a separate application (scheduled separately).

Grzenio
+3  A: 

Ideally you should keep maintenance tasks such as this separate from your web application (either as a scheduled task or Windows service).

But, if you really need to do it this way could create a batch file that does:

iisreset /restart
"C:\Program Files\GnuWin32\bin\wget.exe" -O nul http://www.myapp.com/default.aspx

Then run this batch file as your scheduled task at 12:00. This will restart IIS and warm up your application.

You can get GNU wget.exe from:

WGET for Windows (SourceForge)

Kev
Just a small caveat to note for some rarer scenarios: This won't work in the Web site is configured to use an IIS Web garden. (Well, it will, but it'll only warm up one worker process, the one that spun up to serve the request.)
Nicholas Piasecki
This is true, but OP just needs his background thread to be created/initialised and ready for action rather than his whole app warmed up. Also we'd be into a whole different world of thinking this if it was running on web garden...i.e. concurrency issues.
Kev
A: 

You could also use a Powershell script called by task manager. Here is simple six-line script we use to "warm up" SharePoint servers.

You could repurpose or find a similar script for a basic .NET application.