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
- Task.Run(() => { MyMethod(); });
- HostingEnvironment.QueueBackgroundWorkItem(m => MyMethod());
- 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