What is Azure WebJobs?

Azure WebJob is a feature of Azure App Service that runs a program or script in the background using a WebApp or WebAPI context. There is no additional cost to use WebJob. There are two types of web jobs.

  1. Continuous WebJob.
  2. Triggered WebJob.

Continuous WebJob

Triggered WebJob

Developing Azure WebJob using Visual Studio

Here we will see how to develop Azure WebJobs using Visual Studio.

Let’s create a manual trigger using the NoAutomaticTrigger attribute in the Function.cs file.

[NoAutomaticTrigger]
public void TriggerHandler(TextWriter log)
{
    try
    {
        log.WriteLine("Trigger is Fired");
    }
    catch (Exception ex)
    {
        log.WriteLine("Exception in Trigger Handler", ex);
        throw ex;
    }
}

In Program.cs file contains the main method, call the manual trigger using the JobHost function like below.

class Program
{
    // Please set the following connection strings in app.config for this WebJob to run:
    // AzureWebJobsDashboard and AzureWebJobsStorage
    static void Main()
    {
        var config = new JobHostConfiguration();
        
        if (config.IsDevelopment)
        {
            config.UseDevelopmentSettings();
        }
        
        var host = new JobHost(config);
        host.Call(typeof(Functions).GetMethod("TriggerHandler"));
    }
}

Deploy Azure WebJob In Azure App Service

That’s it, I hope you have learned how to develop and deploy an Azure WebJobs in Azure App service. Feel free to fill up the comment box below if you need any assistance.