3

I have a MVC C# web application with an efficiency problem. We have a controller method users can hit, which runs a notification process which can sometimes need to churn through 10k+ records, and send out associated notifications. This process can take 15+ minutes sometimes.

My question is just general, any guidance is appreciated.. How would I go about making this process more efficient? Ideally, the user would perform the action to hit our controller and kick off this giant process, and then be returned to normal app usage as the process runs in the background.

Would I just achieve this with asynchronous controller methods, or what?

8
  • This is tricky because of sessions and timeouts. One way is to make calls from the user interface at regular intervals and store progress in a database or similar for a simple way forward. Commented Jul 19, 2019 at 16:59
  • Does the user need to be notified when the process completes? Or is this a "fire and forget" type of situation? Commented Jul 19, 2019 at 17:08
  • this could be totally "fire and forget", as once the process finishes we insert records into a logging database the users can check later and see the records of their action. so i don't think we'd need to worry about session or timeouts or anything. Commented Jul 19, 2019 at 17:12
  • You should be able to accomplish this by setting up your controller method that does the work, and then simply firing it off from the client side with an jQuery.Ajax call. Commented Jul 19, 2019 at 17:22
  • okay, so you mean i shouldn't necessarily need to mess with async methods or anything? how would i get around the fact that the ajax call waits on the response from the server before code can continue running? sorry if this is a total noob question, i'm a total noob at this sort of thing. Commented Jul 19, 2019 at 17:33

1 Answer 1

4

Just because you are running MVC website application, does not mean you can not utilize threading and async processing. I would suggest that you get familiarized with Asynchronous programming in .NET.

With simplest approach you would start new Task and optionally you can subscribe to callback method to do post finish processing if needed.

The trick for MVC, or any other website would be how to start the task and how to get notification back to the user. This would require some client side programming with JavaScript, but I would tip on using the most modern approach: ASP.NET Core with Blazor (Binary Razor) if you tend to do more heavy processing on your website. Blazor technology is still in beta at the time of writing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.