Last post May 22, 2015 03:42 PM by deepalgorithm
May 18, 2015 04:20 AM|VansFannel|LINK
I'm developing an ASP.NET MVC Web Api 2 app with C# and .NET Framework 4.5.1.
Sometimes, when user calls a get on an `ApiController` I have to run a task in background. The task will fill up a database table with more data.
Searching on Internet I have found this article,
How to run Background Tasks in ASP.NET. And I want to use
HangFire. But reading its documentation I haven't found a way to use it without using OWIN on my ASP.NET Web Api app (I'm not using it right now).
Is there a way to use Hangfire without OWIN? or maybe, is there another option to run background tasks on an ASP.NET Web Api 2 app?
May 19, 2015 10:11 PM|Krunal Parekh|LINK
Running long tasks in web api is not recommended.
ASP.NET executes your web site (or web application) in an AppDomain, separated from other web sites (or web applications) on the same server. There are many reasons why this AppDomain may be shut down; modern versions of IIS recycle the entire process every
29 hours by default just to keep things clean. Also, you have to take into consideration unmanaged shutdowns: hard drive failures, hurricanes, etc.
but if you have to this then please see below article.
Please see this:
If you are able to separate the both logic of long running task and web api then I would suggest to use windows service to populate the data. you could put some flags in the database that windows service will monitor and produce your data when required.
Hope this helps.
May 22, 2015 03:42 PM|deepalgorithm|LINK
I've had to do similar things. You want to use HostingEnvironment and the QueueBackgroundWorkItem method.
Check out the following post about this subject: