Jean Louis
Jean Louis

Reputation: 1555

ASP.NET MVC: Executing a slow operation on the server and getting its state

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:

  1. Sending the first ajax-request (the form data) to runs this slow operation.
  2. 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?

Upvotes: 2

Views: 395

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038850

How can I run operation on the server that will be processed outside a http request

You could run it in a background thread. Either spawn one manually or if you are using .NET 4.0 use TPL.

How can I get state of this operation?

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.

Upvotes: 3

Related Questions