tags:

views:

73

answers:

4

Greetings folks,

The ASP.NET application I'm maintaining has a fairly long start up procedure. A number of data files are updated, etc. I've been asked if there is a way for the application to return a wait screen (static if necessary) while Application_Start is running?

+4  A: 

No, there's not. ASP.Net needs to initialize the pipeline and everything else just to get to the point of being able to actually handle the request.

Prior to that point, .Net has no idea what the request is, nor what the potential outcome might be. For example, it might be a web service call which has no response. Or the request might cause a document to download at which point you don't want to have any data sent to the client yet.

Instead, I'd look into two things. First, how to reduce the app_start time; and, second, why would an application_start event be kicked off more than once in a blue moon.

Chris Lively
+1 for asking why this is happening at all
egrunin
The worker process could be recycled for any number of reasons, including high traffic and no traffic. Would that cause an Application_Start event?
Greg
@Greg: No, the Application_Start wouldn't be executed in that case
Claudio Redi
Unfortunately, I didn't design or do the initial creation of the app. :p The app shouldn't restart on a consistent basis and when it does I hope to be the person doing it. The question came up in the case of an unexpected restart. Thanks for the answers!
Falconeer
+1  A: 

I don't think you can accoplish what you want very easily, but I would recommend precompilation. Pre-compiling your code saves a lot of time when deploying and getting that app started up.

How to: Precompile ASP.NET Web Site Projects

From Microsoft: Precompiling an ASP.NET Web site project provides faster initial response time for users since pages do not have to be compiled the first time they are requested. This is particularly useful for large Web sites that are updated frequently.

AGoodDisplayName
+2  A: 

You could theoretically have a basic HTML page for your wait screen that (using javascript) loads one of your asp.net pages in an iframe and redirects to the main app landing page when it loads, but that's terrible hackery and I'd question the value of it, myself.

Chris
Agreed. Hackery (and javascript) are things I try to avoid as much as possible. :p
Falconeer
+1  A: 

Here's a possible solution:

You could, in your App Start, kick off a worker thread that actually goes off and loads the data and processes everything that you need to do. You'd set an Application() variable to say that the thread is running and that it hasn't completed yet.

Then, whenever you get a request, check that Application() variable and display your "waiting" page (probably something that redirects itself periodically).

Finally, when the worker thread finishes, it can set the Application() variable to indicate that the thread is complete.

Something (very roughly) like this> In AppStart:

Application("StartupProcessingComplete") = False  
t = New Threading.Thread(AddressOf WorkerFunction)  
t.Start()  

In the WorkerFunction:

<Do the work>
Application("StartupProcessingComplete") = True

In your Page Init, check the variable

If Not Application("StartupProcessingComplete") Then
    <Redirect to "Wait" page>
Endif
Richard
Thanks kindly for the idea! I'll pass it along, but my feeling has been that the effort involved isn't worth the payback. But I'm glad to have a backup if the powers that be decide they want to go forward with it.
Falconeer