ASP.NET Application log while code is running / progress bar

青春壹個敷衍的年華 提交于 2019-12-10 19:29:35

问题


I’m building a OCR scanning module in my ASP forms webapplication. As you may know a operation like that can take some time. Therefor I’m using a background service application that responds to a message queue that runs the code so the user does not even have to stay on the same webpage.

What I would like to do is inform the user what is going on while the service is running. If lets say the user uploaded 5 documents I would like to see something like this appear in a literal, label or repeater control. These items do not have to be saved in a database and I don’t want then to.

Processing document 1 of 5
Document 1 processed with code 6732842
Processing document 2 of 5
Document 2 processed with code 8732457
Processing document 3 of 5
Document 3 processed with code 8725347
Processing document 4 of 5
Document 4 could not be processed “no OCR string recognized”
Processing document 5 of 5
Document 5 processed with code 4372537
Completed: Processed 4 of 5 documents received

If an error occurred I would like to see something like this

An error occurred. The scanning process has been stopped.

I have some idears but I don’t know what’s the best practice.

Option 1:
I could save above items in a static class and let javascript post every 5 sec. to get that value via a web method.

Option 2:
I could save above items in the session returning a updated session object when I let JavaScript post every 5 sec. I don’t know if this is available when using a service Application.

If you have any other options (preferably better ones) that would be greatly appriciated.

Thanx in advance.


回答1:


Save the progress items in a database , give each user's upload with a different id, publish this data with a web service. In the browser, use JavaScipt to retrieve the progress from the web service.
Of course, the database need to delete periodically, e.g., every minitue.




回答2:


I wish I could give you a working example, but what you're wanting to do is not easy, and is made even more difficult by the fact that you're not using ASP.NET MVC which makes async work easier. You're going to need to write a series of asynchronous tasks to do some work for you. This article will give you a good start: http://blogs.msdn.com/b/tmarq/archive/2010/04/14/performing-asynchronous-work-or-tasks-in-asp-net-applications.aspx



来源:https://stackoverflow.com/questions/13069829/asp-net-application-log-while-code-is-running-progress-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!