How to calling a function in Azure Continuous Webjob every n minutes

Forums C#How to calling a function in Azure Continuous Webjob every n minutes
Staff asked 2 years ago

I have a function that is in a continuous Azure WebJob and that function is required to be called once every 5 minutes.

Code in Program.cs

static void Main()
{
    var config = new JobHostConfiguration();

    if (config.IsDevelopment)
    {
        config.UseDevelopmentSettings();
    }

    var host = new JobHost(config);
    host.Call(typeof(Functions).GetMethod("StartJob"));
    host.RunAndBlock();
}

Code in Function.cs

[NoAutomaticTrigger]
public static void StartJob()
{
    checkAgain:
    if (DateTime.Now.Minute % 15 == 0 && DateTime.Now.Second == 0)
    {
        Console.WriteLine("Execution Started on : " + DateTime.Now);
        //Execute some tasks
        goto checkAgain;
    }
    else
    {
        goto checkAgain;
    }
}

 

Subscribe

Select Categories