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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With