简体   繁体   中英

ASP.Net MVC Long Running Process

I have a requirement to produce a report screen for different financial periods. As this is quite a large data set with a lot of rules the process could take a long time to run (well over an hour for some of the reports to return).

What is the best way of handling this scenario inside MVC?

I am concerned about:

  • screen locking
  • performance
  • usability
  • the request timing out

Those are indeed valid concerns.

As some of the commenters have already pointed out: if the reports do not depend on input from the user, then you might want to generate the reports beforehand, say, on a nightly basis.

On the other hand, if the reports do depend on input from the user, you can circumvent your concerns in a number of ways, but you should at least split the operation into multiple steps:

  1. Have a request from the browser kick off the process of generating the report. You could start a new thread and tell it to generate the report, or you could put a "Create report" message on a queue and have a service consume messages and generate reports. Whatever you do, make sure this first request finishes quickly. It should return some kind of identifier identifying the task just started. At this time, you can inform the user that the system is processing the request.
  2. Use Ajax to repeated poll the server for completion of the report using the given identifier. Preferably, the process generating the report should report its progress and this information should be provided to the user via the Ajax polling. If you want to get fancy, you could use SignalR to notify the browser of progress.
  3. Once the report is ready, return a link to the user where he/she can access the report.

Depending on how you implement this, the user may be able to close the browser, have a sip of coffee and come back to a completed report.

In case your app is running on Windows Server with IIS your ASP.Net code can create a record in db table which will mean that report should be created.

Then you can use Windows Service or Console App which might be running on the same server and constantly checking if there any new fields in the table. This Service would create a report and during creation it should update table field to indicate progress. Your ASP.net page might be displaying progress bar, getting progress indication from db using ajax requests or simply refreshing the page every several seconds.

If you are running on Windows Azure cloud you might use WebWorker instead of Windows Service

For screen locking on your page you may use jquery Block-UI library

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM