1

I have a requirement to run an event handler, which should "run all the time in background". The application also has to be running in IIS, as Devops team finds it easier to install and deploy IIS hosted applications, compared to a windows service. The event handler in itself should not take more than 5 seconds to process one event

Considering the above requirement, i have done some googling and found the following approaches

  1. Task.Run(() => { MyMethod(); });
  2. HostingEnvironment.QueueBackgroundWorkItem(m => MyMethod());
  3. Use Hangfire

Also understand that either of these approaches, needs to be used in conjunction with IRegisteredObject, so that application pool recycles are handled gracefully.

Ref

Can somebody suggest which of the above approaches(or anyother) should be selected, and why?

References -

The Dangers of Implementing Recurring Background Tasks In ASP.NET

Making ASP.NET application always running

Task.Run vs BackgroundWorkItem

Anoop
  • 418
  • 6
  • 19
  • 1
    Your team would find it a lot easier if the Windows Services were created with [Topshelf](http://topshelf-project.com/). Windows Services are the correct way to run a process in the background, that's not what IIS is for. – mason Oct 10 '17 at 15:19
  • Topshelf was the solution development team(my) proposed, but like i mentioned the devops team find the deployment of IIS hosted application easier(As they already have a lot many IIS hosted applications). I am trying to build a strong case, for Hangfire – Anoop Oct 11 '17 at 08:02
  • 1
    We ended up with windows services for big jobs and Hangfire for little jobs=( It would be great, if we could create asp.net service with full backgroud job support. Inspecting this now:https://blogs.msdn.microsoft.com/cesardelatorre/2017/11/18/implementing-background-tasks-in-microservices-with-ihostedservice-and-the-backgroundservice-class-net-core-2-x/ – Vladislav Apr 17 '18 at 14:57

0 Answers0