Ev.
Ev.

Reputation: 7589

How do I handle a long request in an MVC app

So I have an MVC application in which an admin can log in, and upload a CSV of user detaisl (firstname/lastname/address/phone). This CSV is then imported into to the database.

This works fine for a small CSV, but not so much for one with lots of rows.

I was thinking it might be nice to do this task asynchronously, although I'd prefer not to process it in a scheduled task.

Also, I'd like to be able to poll the process with JavaScript to get a message of how the import is going. For example, after 10 secs, "3000 of 100000 subscribers have been imported".

How should I tackle this one?

Upvotes: 2

Views: 1120

Answers (1)

Yusubov
Yusubov

Reputation: 5843

The quick solution would be to process it in a separate thread. That will make sure that process is going without any effect to your current Web UI thread.

Another solution is somewhat similar that you have mentioned with async controller.

Solution #2: Look at this very useful post for a exact solution that you are asking for - Need an ASP.NET MVC long running process with user feedback.

Upvotes: 2

Related Questions