开发者

Is there a way for an ASP.NET app to show a wait screen to the user that kicks off the Application_Start event?

Greetings folks,

The ASP.NET application I'm maintaining has a fairly long start up procedure. A number of data files are upd开发者_如何学运维ated, 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?


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.


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.


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜