How to Schedule a task in Azure Worker role?

0 votes

Below code demonstrates my Azure Worker role running that performs a task every day at 12 PM:

public override void Run()
{
    try
    {
        while (true)
        {
              int time = Convert.ToInt32(DateTime.Now.TimeOfDay);
              if (time == 12)
              {
                   DoSomethingElse();
              }
        }

    }
    catch (Exception ex)
    {
        Log.Add(ex, true);
    }            
}

Here DoSomethingElse() is a method to send an email at every day 12 PM, and also fires once and only once per day.

How can I implement a scheduler that fire when the time is 12PM and execute DoSomethingElse()? And is this code the best method to use or should I use any 3rd party tool?

Jul 1 in Azure by sabby
• 4,350 points
17 views

1 answer to this question.

0 votes
You can simply have a message on Azure Queue that is time-delayed to not show up until noon. This also helps deal with multi-instance scenarios: If you're running two instances of your role, you don't want the same scheduled task running twice, so you need a way to have only one of those instances execute this code. This is easily handled via queue message, or you could run scheduler code on a single instance by using something like a blob lease as a mutex.
answered Jul 1 by Perry
• 17,010 points

Related Questions In Azure

0 votes
1 answer

How to identify a deadlock in SQL Azure?

Monitoring of SQL Azure is more limited ...READ MORE

answered Jun 19, 2018 in Azure by club_seesharp
• 3,450 points
181 views
0 votes
1 answer

Azure Blob: How to open a file in browser without downloading it?

First, because I was using a byte[] the controller ...READ MORE

answered Jun 20, 2018 in Azure by club_seesharp
• 3,450 points
2,277 views
0 votes
1 answer

How to get the list of names of Azure blob files in a container?

We can get some additional info like Size, ...READ MORE

answered Jun 27, 2018 in Azure by club_seesharp
• 3,450 points
517 views
0 votes
1 answer

How do you wait on a Task Scheduler task to finish in a batch file or C#?

From batch file, query the task status, ...READ MORE

answered Sep 24, 2018 in Azure by club_seesharp
• 3,450 points
50 views
0 votes
1 answer
0 votes
1 answer

Quering all the rows in Azure table Storage.

Refer the following code: var acc = new ...READ MORE

answered Apr 12 in Azure by Prerna
• 1,940 points
11 views
0 votes
1 answer
0 votes
1 answer

I want to queue time-based tasks in Azure

You need to use a scheduled task. ...READ MORE

answered Jul 2 in Azure by Perry
• 17,010 points
12 views
0 votes
1 answer

How to create a sub-container in Azure?

You can create a container named "content" and ...READ MORE

answered Jun 28 in Azure by Perry
• 17,010 points
23 views
0 votes
1 answer

How do I upload a picture to Windows Azure Website?

Check out this example: @model List<string> ...READ MORE

answered Jun 27 in Azure by Perry
• 17,010 points
32 views