# Is hangfire suitable to run "infinite loop" job?

**URL:** <https://discuss.hangfire.io/t/is-hangfire-suitable-to-run-infinite-loop-job/1473>\
**Category:** question\
**Created:** [October 27, 2015, 12:11pm UTC](https://discuss.hangfire.io/t/is-hangfire-suitable-to-run-infinite-loop-job/1473 "2015-10-27T12:11:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![christopheblin](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/christopheblin/32/435_2.png) [@christopheblin](https://discuss.hangfire.io/u/christopheblin)\
**Post date:** [October 27, 2015, 12:11pm UTC](https://discuss.hangfire.io/t/is-hangfire-suitable-to-run-infinite-loop-job/1473/1 "2015-10-27T12:11:11Z")

</div>

I’d like to listen to a message bus inside my WEB API 2 application. The context is that I have multiple web api applications and they need to interact with each other.

At the moment, I instanciate the message bus client inside a method called by WebActivator:PreApplicationStartMethod.

The problem is that if multiple workers start on IIS, I have multiple instances of the message bus client which is not what I want (ex: the sync will be launched multiple times) !

The second problem is that if there is no request on the web api for a while, IIS stops the application and so no one listen to the message bus …

Is hangfire suited for this requirement ? From what I understand, hangfire is not suited for this kind of “job” since the “job” never finishes

Is a windows service with the message bus client a better alternative ?

---

<div class="post-metadata">

**Author:** ![burningice](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/burningice/32/53_2.png) [@burningice](https://discuss.hangfire.io/u/burningice)\
**Post date:** [October 27, 2015, 9:18pm UTC](https://discuss.hangfire.io/t/is-hangfire-suitable-to-run-infinite-loop-job/1473/2 "2015-10-27T21:18:29Z")

</div>

You can implement your job as a [IBackgroundProcess](https://github.com/HangfireIO/Hangfire/blob/master/src/Hangfire.Core/Server/IBackgroundProcess.cs), which HangFire will keep executing infinitely - you can add an interval by calling WaitOne on the CancallationToken passed as a parameter to the Execute method.

An example is here [https://github.com/HangfireIO/Hangfire/blob/master/src/Hangfire.SqlServer/ExpirationManager.cs#L98](https://github.com/HangfireIO/Hangfire/blob/master/src/Hangfire.SqlServer/ExpirationManager.cs#L98)
