开发者

Can I use async controllers in the following scenario?

开发者 https://www.devze.com 2023-03-17 05:14 出处:网络
I have an application in Asp.net MVC where at some point I would like to display a modal dialog to the user that would display process execution progress indicator.

I have an application in Asp.net MVC where at some point I would like to display a modal dialog to the user that would display process execution progress indicator.

The process behind the scenes does a lot of database data processing (based on existing data it generates lots of resulting records that get written back to database as well). Process may take anything from a brief moment to a very long time (depending on existing data).

Application will initiate this process asynchronously (via Ajax request) and display progress in the same manner.

The problem

I've read a bit about Async controllers where one can asynchronously start a process and will informed about the end of it but there's no progress indication and I'm not really sure how browser timeouts are handled. As far as the client goes an async request is the same as synchronous one. Client will therefore wait for response (as I understand it). the main difference being that server will execute something in async manner so it won't block other incoming requests. What I should actually do is:

  1. make a request that would start the process and respond to the client taht process has started.
  2. client would them periodically poll the server for process progress status getting immediate response back with percentage value (probably as JSON)
  3. when progress would be 100% it would mean that it ended so client would know to make a request for results.

I'm not convinced that async controllers work this way...

The thing is that I'm not really sure I understand async controllers hence am not sure which approach should I use approach this problem as just described? I see two possibilities myself:

  1. Asp.net MVC Async controllers if they can work this way
  2. Windows Service app that processes data on request and reports its progress - this service would be started by writing a particular record to DB using a normal controller action; that would start it and then service would be writing its progress status to DB so my Asp.net MVC app would be able to read it on client process polling requests.开发者_如何转开发


I haven't used Asynch controllers myself in a project. However here's a link to someone who has.

asynchronous-processing-in-asp-net-mvc-with-ajax-progress-bar

I have personally used Number 2 in a large production project.

Number 2 was a Service App running on a separate server using OpenSSH to communicate between the two servers. We'd poll for progress periodically to update the progress bar to the clients UI via AJAX.

Additionally by separating your web server from your long running process you are separating your concerns. You web server is not interested in writing files to disk, handling IO, etc and so shouldn't be burdended with such.

If your long running process has to be killed or fails then this wont affect your web server handling requests, and processing transactions.

Another suggestion would be for an extremely long running process is not to burden the client with waiting, give them an option to come back later to see the progress. I.e. send them an e-mail when its done.

Or actually show them something interesting, in our case we had a signed Java Applet show exactly what their process is doing at that exact moment.

0

精彩评论

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