I’m developing a web application based on ASP.NET MVC.
There are a large database. Users can search in this database using custom filters (html-form with options). After users submit the form and wait a result. It’s very slow operation. But it’s a not question of database optimisation or query optimisation.
So, there is slow operation. I want to run this operation and get it state from time to time without a page realoding.
I see it like:
- Sending the first ajax-request (the form data) to runs this slow operation.
- Sending ajax-requests from time to time to get info about the operation.
Questions:
1. How can I run operation on the server that will be processed outside a http request?
2. How can I get state of this operation?
You could run it in a background thread. Either spawn one manually or if you are using .NET 4.0 use TPL.
Once started the operation should be assigned an unique ID and returned immediately to the client. Then when the operation progresses in the background thread it could update its progress using the ID. For example you could use the Application state to store this progress. The the client will poll the server at regular intervals to fetch the progress.