ASP.Net MVC Long Running Process

后端 未结 2 1980
感情败类
感情败类 2021-01-25 07:49

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

相关标签:
2条回答
  • 2021-01-25 08:09

    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

    0 讨论(0)
  • 2021-01-25 08:14

    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.

    0 讨论(0)
提交回复
热议问题