Search code examples
azureazure-webjobsazure-webjobssdk

Azure WebJobs SDK - in what scenarios is creation of a JobHost object required?


Most of the samples associated with the Azure WebJobs SDK have startup code that looks like this:

static void Main()
{
    JobHost h = new JobHost();
    h.RunAndBlock();
}

However you can also kick off a WebJob without creating a JobHost object like this:

static void Main()
{
    // Do something...
}

In what scenarios is the JobHost necessary?


Solution

  • You need the Jobs Host Configuration when you want to interact with Azure Storage (table storage, queues, blobs) or ServiceBus and if you want to expose your functions to the Azure WebJobs Dashboard.

    This is some code I use in a WebJob that doesn't use JobHost

    static ISubscriptions _subscriptions;
    
    static void Main()
    {
        Process();
    }
    
    public static void Process()
    {
        _subscriptions.DoWork();
    }