Neo
Neo

Reputation: 16219

Does Azure Webjob support Async execution

I want to execute my Azure Webjob methods async but I wonder Azure Webjob supports Async Execution or not.

How can I execute webjob methods ProcessSub1Messages and ProcessSub2Messages asynchronously?

namespace WebJob1
{
public class Functions 
{
      public static void ProcessSub1Messages([ServiceBusTrigger("TestTopic", "Sub1")] BrokeredMessage message,
        TextWriter logger)
        {   
            Console.WriteLine("Webjob Start for Sub1 {0} {1}", message.MessageId, DateTime.Now);
            Thread.Sleep(100000);
            Console.WriteLine("Webjob End for Sub1 {0} {1}", message.MessageId, DateTime.Now);
        }

        public static void ProcessSub2Messages([ServiceBusTrigger("TestTopic", "Sub2")] BrokeredMessage message,
        TextWriter logger)
        {
            Console.WriteLine("Webjob Start for Sub2 {0} {1}", message.MessageId, DateTime.Now);
            Thread.Sleep(100000);
            Console.WriteLine("Webjob End for Sub2 {0} {1}", message.MessageId, DateTime.Now);
        }
}
} 

Upvotes: 0

Views: 618

Answers (1)

Victor Hurdugaci
Victor Hurdugaci

Reputation: 28425

Yes, the WebJobs SDK supports async. Just change the return type of the function from void to Task:

 public static async Task ProcessSub2Messages(
    [ServiceBusTrigge(("TestTopic", "Sub2")] BrokeredMessage message,
    TextWriter logger)
    {
        // async operations here
    }

Upvotes: 2

Related Questions