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.

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