How to create a long running background task from MVC

asp.net-mvc async-await c# entity-framework multithreading

Question

In VS 2013, I'm using EF6 and MVC 5. I want to set up a long-running process to execute in the background and then return quickly to the web controller because it is resulting in timeout errors. An SQL server database will get updates from the background task. In essence, I require a. blaze and forget functionality. There seem to be several choices:

  1. Use a Windows service to execute the jobs and write their details to a server UPDATE: These were the choices made.
  2. Use async - This doesn't seem like a very safe choice.
  3. Use HostingEnvironment. Method QueueBackgroundWorkItem

Since option 3 keeps all the code in one solution, it would be preferred. Could you please discuss the advantages and disadvantages of each and, if feasible, provide practical examples of number 3?

1
5
11/1/2016 10:47:04 AM

Accepted Answer

The long-running process could be stopped, for example, if the application pool recycles, according to HostingEnvironment.QueueBackgroundWorkItem, which is a valid solution.

Running it as a scheduled process, for instance using Quartz.NET, would be a preferable choice.

6
5/23/2017 12:17:08 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow