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, 2019 in Azure by sabby
• 4,370 points
1,428 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, 2019 by Perry
• 17,100 points

Related Questions In Azure

0 votes
1 answer

How can I schedule a pipeline to run in azure datafactory?

You can use the scheduler trigger or ...READ MORE

answered Jan 2, 2020 in Azure by Sirajul
• 59,230 points
953 views
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
2,629 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
24,651 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
21,802 views
0 votes
1 answer

How to add a body to a HttpWebRequest that is being used with the Azure Service management API?

The following code should help: byte[] buf = ...READ MORE

answered Apr 3, 2019 in Azure by Prerna
• 1,960 points
2,655 views
0 votes
1 answer

Quering all the rows in Azure table Storage.

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

answered Apr 12, 2019 in Azure by Prerna
• 1,960 points
4,840 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, 2019 in Azure by Perry
• 17,100 points
1,215 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, 2019 in Azure by Perry
• 17,100 points

edited Oct 7, 2021 by Sarfaraz 1,953 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 28, 2019 in Azure by Perry
• 17,100 points
1,650 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP