views:

112

answers:

2

If I wanted to display a loading page while some script was running, how would I go about it?

It seems that a view is rendered when the controller's code has finished executing, but I need there to be something displayed to the user as the code is doing a fair amount.

Thanks for any pointers.

+1  A: 

You'll either need to load that page in a jQuery call, as suggested by Jason, and hope it doesn't time out, or move the code that is being executed into a standalone component; typically a Windows Service, and then communicate with it to start it processing and to receive a message when it's done (I generally use MSMQ).

Noon Silk
A: 

YOU SHOULD NOT RUN LONG TASKS IN WEB REQUEST.
Instead you have to do following:

  1. In your action get a working new thread that does it.
  2. Render the view that will query about the progress periodically (using Ajax request or normap posts). It is another action.
  3. If the job is done, execute the 3rd action that will return the actual result.

Here is one example (for WebForms though). But instead of starting new thread obtain one from ASP.NET pool.

Dmytrii Nagirniak
Thanks - I'll need to do a bit of playing around with this
Paul
That's fun! Who and for what reason downvoted the answer??
Dmytrii Nagirniak
I didn't downvote it, but I suggest it was because you proposed using threads. Which I think is a bad idea.
Noon Silk
The explanation would be fair together with downvoting.Anyway, nobody likes threads but in this case you cannot do everything in a single thread because of the nature of Web Application.
Dmytrii Nagirniak