Search⌘ K
AI Features

Using Timer Triggers

Explore how to implement timer triggers in Azure Functions to execute code at scheduled intervals. Understand the configuration of timer triggers using the TimerInfo parameter and Cron expressions. Learn to write and adjust Cron schedules to automate tasks efficiently with Azure Functions.

A timer trigger is used to execute a function at specific timed intervals. This is how we can turn a function into a scheduled job. We have an example of this in the following interactive playground:

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

namespace TimerTriggerDemo
{
    public class Functions
    {
        [FunctionName("TimerDemo")]
        public void Run([TimerTrigger("0 * * * * *")]TimerInfo myTimer, ILogger log)
        {
            Console.WriteLine($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}
Function with a timer trigger

Timer trigger basics

To configure a timer trigger on a function method, we need to pass a parameter into the method of the TimerInfo type. This parameter needs to have a TimerTrigger attribute with a Cron expression, which is used to configure the schedule. We have an example of this in line 10 of the Functions.cs file.

In our example, the expression is 0 * * * * ...