4

I am in need of some advice on the best approach to dynamically creating some form of scheduled task at web application level. The scheduled task will be pulling information from an external API endpoint to store within a database at regular intervals until a specific end time.

Normally, I would create a Windows Service that will carry out this job for me. Unfortunately, the site administrator could create multiple tasks to query different criteria from the external API. So there could be multiple tasks running.

I have been working on implementing a background worker thread that runs on a timer. Would this be the best approach? Or would using something like Hangfire or Quartz.net be a better solution to ensure my background process is constantly running?

I don't know if it's feasible inside a web application to be ensure a task can constantly be run when required for a specific duration of time.

SurinderBhomra
  • 2,169
  • 2
  • 24
  • 49

1 Answers1

1

I tried to use Hangfire and Quartz.Net and in my opinion both of them are very good for scheduling task. Hangfire has a good interface for managing scheduled tasks, but as I encountered some problems after publishing the application on IIS, I switched to use Quartz.Net which works perfectly with Keep Alive Service For IIS 6.0/7.5. So, for using Quartz.Net you might have a look at Scheduled Tasks In ASP.NET With Quartz.Net. On the other hand, in order to make your published application to be alive after application pool recycling, IIS/Application restarting, etc. just install Keep Alive Service For IIS 6.0/7.5 on the server to which you publish your application. For detailed information regarding to these problems have a look at my answers on the pages below:

Hope this helps...

Community
  • 1
  • 1
Murat Yıldız
  • 11,299
  • 6
  • 63
  • 63
  • 2
    If you have full control over the server, then you can configure Hangfire or Quartz.Net to run the jobs using a background service instead of running them in IIS. This makes the jobs a lot more stable. I found Hangfire easier to configure for this with its support for MSMQ. – Chris Chilvers May 09 '16 at 08:24
  • 1
    @ChrisChilvers Actually it would be better to use the scheduling as a background service instead of running them in IIS. So, for an MVC application, how can it be performed? Could you please explain step by step? Thanks. – Murat Yıldız May 09 '16 at 09:37
  • 1
    @MuratYıldız Thanks for the response, I will take a look at the links you've posted. – SurinderBhomra May 09 '16 at 10:17
  • 1
    @MuratYıldız The simplest option for that is to use Hangfire. The Hangfire documentation has a whole section on the different methods of background processing, including processing jobs in a windows service and configuring hangfire to use SQL server with MSMQ. – Chris Chilvers May 09 '16 at 10:29
  • @ChrisChilvers I have a look at Hangfire Documentation and now I have two issue about which I need to be clarified. Could you please clarify us regarding to the following issues? >>> –  May 09 '16 at 18:20
  • @ChrisChilvers **1)** What is MSMQ and what do you mean with ".. to run the jobs using a background service instead of running them in IIS"? **2)** I use ASP.NET Identity 2, and I integrated Hangfire to my project. However, I cannot integrate dashboard to authentication (I need to use it on the IIS as localhost). I tried to apply the methods as explained on [here](http://stackoverflow.com/questions/29441634/why-is-hangfire-requiring-authentication-to-view-dashboard) and [here](http://docs.hangfire.io/en/latest/configuration/using-dashboard.html) but not worked. Any idea? –  May 09 '16 at 18:20
  • @ChrisChilvers I tried Hangfire and see that Hangfire continues to firing triggers even if I stop the application and application pool on IIS. The only way o stop firing is to remove it from dashboard, but after starting the application it is created again. Any idea to fix this problem? –  May 10 '16 at 09:27