Create timer trigger Azure function in Visual Studio 2019

How To Create Azure Functions Time Trigger From Visual Studio 2019

This Azure tutorial will discuss the steps to Create Azure Function Time Trigger From Visual Studio.

Create timer trigger Azure function in Visual Studio 2019

Well, here we will discuss How To Create And Deploy Azure Functions Time Trigger From Visual Studio 2019. Let’s start Creating the Azure Functions Time Trigger From Visual Studio 2019.

Before starting the actual development, we should know the Prerequisites

Prerequisites

  • We need an Azure Account or Azure Subscription. Don’t have an Azure Account now? No worries, create an Azure Free Account now.
  • If you don’t have Visual Studio 2019 installed on your machine, install Visual Studio 2019 now. Along with Visual Studio 2019, you need to install the Azure development workload.
  • We need Updated Azure Function tools.
  • You need an Azure Storage Account. If you don’t have an Azure Storage Account till now, create an Azure Storage Account now.

Timer trigger Azure Function Example C#

Well, now we are ready for the development activities with all the Prerequisites needed. Let’s start creating the Azure Function Project.

  1. Now, from your local machine, Open Visual Studio 2019 and click the Create a New Project button. Select the Azure Functions template on the Create a new project window and click the Next button.
azure functions timer trigger

2. You need to provide the details in the window below

  • Project name: Provide the Azure Function Project name
  • Location: You need to choose a location for your Azure Function Project.
  • Solution: Choose to Create new solution

Then, click on the Create button.

azure functions timer trigger example

3. Now, this step is very important. We will have to choose a trigger for our Azure Functions. The role of the trigger is to invoke the Azure Function.

Make sure to choose the Timer Trigger as the template and then provide the below details

Storage Account (AzureWebStorage): choose the Storage Emulator option here.

Schedule: You can keep the CORN expression 0*/5**** as it is. This means the timer trigger Azure Function will execute on each 5-minute interval. If You change it to 0*/3****, the Azure Function will execute on each 3-minute interval. Decide based on your business requirements. Check out more details on the CORN expression now.

Finally, click on the Create button to create the timer trigger Azure Function.

azure functions timer trigger example

Now you can see below the Azure functions timer trigger project was created successfully without any issue

Create Azure Functions Timer Trigger in Visual Studio 2019

Below is the Timer trigger Azure Function Code

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

namespace TimeTriggerAzureFunction
{
    public static class Function1
    {
        [FunctionName("mytimertriggerfunction")]
        public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}

You can see it here

How To develop Azure Functions Time Trigger From Visual Studio 2019

This way, you can Create Azure Functions Time Trigger in Visual Studio. Now, let’s check out the deployment steps.

How To Deploy Azure Functions Timer Trigger From Visual Studio 2019

Follow the below steps to Publish Azure Functions Time Trigger From Visual Studio 2019.

1. Right-click on the Azure Functions Time Trigger project and click on the Publish button

azure function timer trigger visual studio

2. Click on the Azure Functions Consumption Plan, select the Create New option, and click the Create Profile button.

Deploy Azure Functions Time Trigger From Visual Studio 2019

3. Provide the below details as highlighted

  • Name: Provide the name for the Function App
  • Subscription: Choose your correct subscription
  • Resource group: You can choose your existing resource group or click on the New button to create a new Resource Group.
  • Location: Choose a location for your Function App
  • Azure Storage: You can choose your existing storage account, or If you don’t have an existing one, click on the New button to create a new one.

Now click on the Create button.

Publish Azure Functions Time Trigger From Visual Studio 2019

4. Now click on the Publish button from the below window to Publish the Azure Function

Publish Azure Functions Time Trigger using Visual Studio 2019

5. On the next pop-up, click on the Yes button to update the Azure Function version

How to Publish Azure Functions Time Trigger using Visual Studio 2019

Now, your Azure Function will get published successfully. The next step is to verify if it is published successfully, and then We will test if the Azure timer function is working.

Test the Azure Functions Timer Trigger

To check all these things, you must navigate to the Azure Function App you published just now.

1. Log in to the Azure Portal, search for the App services, and then click on the search result. You will find your Azure Function App in the list of app services. Click on your Azure Function App. Then, As shown below, On the Azure Function App page, click on the Functions from the left navigation

How to deploy Azure Functions Time Trigger using Visual Studio 2019

2. On the Azure Function page, click on the Code + Test link from the left navigation, and then to test the Azure Function, if it is working fine as expected, click on the Test/Run button.

How to deploy Azure Functions Time Trigger from Visual Studio

3. The next step is to click on the Run button from the below window

How to publish Azure Functions Time Trigger from Visual Studio

You can see below we got the expected response code i.e. 202 Accepted.

azure function timer trigger visual studio

Select the log as Information to see if the function is executed every 5 minutes. You can see the function execution time on each 5-minute

Deploy Azure Functions Time Trigger from Visual Studio 2017

You may also like following the articles below

Wrapping Up

This article discusses the quick steps to create a timer trigger Azure function in Visual Studio 2019. I hope you have enjoyed this article !!!