Scheduled Task Issue

Fuad Dahlan asked on October 17, 2017 06:56

Hi all,

Does anyone know why the scheduled task is not running on time? It seems like the IIS will go to some sort of sleep mode and scheduled task will not run until IIS is woken up. I've set the Application Pool Timeout to 0 already but it's not working, now I try to set the application pool service to "Always Running", previously it was set to "On Demand".

Thanks.

Recent Answers


Matt Nield answered on October 17, 2017 07:38

There are a number of reasons this could be the case.

  1. The scheduled tasks default behaviour is to run in the ASP.NET process. So if your site suffers a period of activity, the application pool might shut down. If that occurs, then the tasks will stop being executed until the application pool starts up again.
  2. The frequency of your task is based upon a lapsed time between executions. If you want to run a task every 5 minutes that takes 1 minute to complete, then you effectively end up running that tasks every 6 minutes. You can work around this when building your tasks to make sure that you take in to account when the tasks started.

If you want to ensure frequency of tasks, then the best bet (and recommended approach) is to use the Windows Service. This is a service that can be installed with Kentico to enable regular execution of scheduled tasks. Read Configuring scheduled task execution for more information.

There is another option of creating a service to regularly call your website to prevent the application pool from shutting down due to inactivity, but this is something that you would need to create yourself. You would just need to create a windows service and then, in that service make a web request to one or more pages of your site.

An advantage of creating your own service is that you can use this as part of your health monitoring service such as StatusCake, wo you get a double win :)

0 votesVote for this answer Mark as a Correct answer

Fuad Dahlan answered on October 17, 2017 07:48

The reason why I scrap the windows service to run the codes is because I'm using Kentico's calendar to determine if it's weekend or holiday based on what the user put in, if I were to use windows service I can't use Kentico's calendar already right?

In the application, I want the codes to run from Monday to Friday at 11:59pm to change the records in database.

0 votesVote for this answer Mark as a Correct answer

Matt Nield answered on October 17, 2017 10:00

Within reason, you can access most fo the information within Kentico form teh scheduled stasks when executed by the WIndows service. It really depends on what you are accessing and how - so for example, you can't use macros if you use the windows service to process the task.

If you use the last option in my suggestion - creating your own windows service to poll the website, then this will still run the scheduled task through ASP.NET and should have full access to the features and code the you have.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 17, 2017 20:19

Another option is to configure the IIS settings for the site to always be on. You can also set the app pools recycling to happen at a given time or frequency. This would mean the site would always remain "on" until it was caused to shut down.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.