Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top