Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Quartz scheduler stopped running when no activity on the site

I have created asp.net site with quartz scheduler. The job is running in background and there is no other activity on the site.

Quartz scheduler scheduled for every 30 minutes.

After IIS started, Scheduler is running correctly.

But after some time, Scheduler stopped running (about 1 hour).

If have one or more activity on site as user login or view dashboard then Scheduler runs correctly.

But when have no activity on site it stops running.

How to keep alive my Scheduler for all the times when no activity on site?

P/s: I know my question can be duplicate with other question. But i still ask because i can not comment to ask in answers of other question.

Edit:

Day Running at: 7/14/2016 4:00:00 AM
--
Day Running at: 7/14/2016 4:30:00 AM
--
Day Running at: 7/14/2016 5:00:00 AM
--
Stopped running
--
Day Running at: 7/14/2016 2:00:00 PM
--
Day Running at: 7/14/2016 2:30:00 PM
--
Day Running at: 7/14/2016 3:00:00 PM
--
Stopped running
--
like image 870
TonyBui Avatar asked Dec 25 '22 03:12

TonyBui


2 Answers

By default, IIS will unload your application if the application receives no requests for a period of time.

You can configure IIS to never unload your application.There are plenty of reasons IIS will unload your application - make sure you disable all of them. It is in the application pool settings, better go to Advanced Settings and pass carefully through all of them.

On a side note, if you have a background job you need to reliably run on schedule, why not deploy it in a Windows service, in addition to the web application? Web applications are best at serving incoming requests, not running scheduled jobs.

UPDATE

Check out these in Advanced Settings of your application pool:

  • Process Model / Idle Time-out and Idle Time-out Action
  • Recycling / Regular Time Interval, Request Limit, Private Memory Limit, Virtual memory Limit
like image 196
felix-b Avatar answered Jan 13 '23 10:01

felix-b


Normally you shouldn't use ASP.NET for recurring tasks because it is not built for that, it's recommended to use a Windows Service for that.

However, you could use WebBackgrounder. Scott Hanselman seems to endorse it ;) He also demonstrates how to use Quartz.NET along with it.


Or you could start a thread that generates requests from your app into itself each minute, to keep it up:

    protected void Application_Start()
    {
        // ...

        ThreadPool.QueueUserWorkItem(o => PingMyself());
    }

    private static void PingMyself()
    {
        var webClient = new WebClient();
        while (true)
        {
            Thread.Sleep(TimeSpan.FromMinutes(1));
            webClient.DownloadString("http://my.public.address.com");
        }
    }
like image 37
Andrei Rînea Avatar answered Jan 13 '23 10:01

Andrei Rînea