1

I have my worker role and I need to run a specific task exactly at 10 AM each day.

public class WorkerRole : RoleEntryPoint
{
    public override void Run()
    {                  
        while (true)
        {
            if (DateTime.Now.Hour == 10)
            {
                //Do Specific timer Job();
            }
            //Do Normal Worker process();

            Thread.Sleep(TimeSpan.FromMinutes(1));

        }
    }

This runs the timer job multiple times since I get only the hour, I cant just check it with a specific time say 10.00 since there is a chance that it might be skipped by the main worker process.

I need to know the ideal way to implement this.

I have seen this link and those mentioned in the answers,

How to Schedule a task in windows azure worker role

But I need a solution without using azure scheduler, or any third party tool :( Anyway by which I can use timers to check with the specific time ?

Community
  • 1
  • 1
wickjon
  • 900
  • 5
  • 14
  • 40
  • Can you not use Quartz.Net library as mentioned in the link you provided? It is open source, extremely robust and highly configurable. – Gaurav Mantri Aug 26 '14 at 10:19

2 Answers2

1

Probably you can use Azure WebJobs

http://azure.microsoft.com/en-us/documentation/articles/web-sites-create-web-jobs/#Scheduler

And also, today's post from Scott Hanselman with variety of libraries including Quartz.Net from previous commentator.

http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx

Vladmir
  • 1,255
  • 9
  • 13
0

Insert a simple queue message and set the visibility timeout of that message. So that the message will be visible only at that time and you can do the action.

public class WorkerRole : RoleEntryPoint
{
    public override void Run()
    {                  
        while (true)
        {
            CloudQueueMessage queuemessage = queuestorage.GetMessage(queue name)
            if(queueMessage.exist && queueMessage insertion time < 10 am today)
            {
                if (DateTime.Now.Hour >= 10)
                {
                    //Do Specific timer Job();
                    //Delete the queue message and insert new one for the task next day.
                }
            }

            //Do Normal Worker process();

            Thread.Sleep(TimeSpan.FromMinutes(1));

        }
    }
}
djn
  • 103
  • 8
  • But creating another queue for this, involves additional pricing right ? I am looking for may be less simpler approach. – wickjon Aug 26 '14 at 14:13