0

I have an application that sends automatic mails via a worker role. When I debug my application in Visual Studio my task that I set OnStart() in the WorkerRole.cs works perfectly, I receive a mail every 5 minutes (for test purposes). My Code in WorkerRole.cs:

   public override bool OnStart()

    {
        ScheduledTaskTimer.Elapsed += new ElapsedEventHandler(ScheduledTaskTimer_Elapsed);
        // ScheduledTaskTimer.Interval = 86400000;
        ScheduledTaskTimer.Interval = 180000;

        ScheduledTaskTimer.Enabled = true;
        return base.OnStart(); }

But when I deploy to Windows Azure, my worker role does not seem to work. I never receive any mail.. I don't know how to check if the worker role is actually running..

David Makogon
  • 69,407
  • 21
  • 141
  • 189
Yunieke
  • 43
  • 2
  • 9
  • 1
    It's almost certainly the case that your worker role is running but the code you're using to send mail isn't. How are you sending the mail? What mail server are you using? Is it reachable? – user94559 May 15 '12 at 16:59
  • I'm using gmail.. and it appears to be working – Yunieke May 16 '12 at 07:10

2 Answers2

1

You can view the state of your worker role using the silverlight interface provided by Microsoft at: http://windows.azure.com

If you see that your WorkerRole is never in the "Ready" state, it often means that your WorkerRole can't start. Which means an exception is probably thrown in the OnStart() method.

If you want to understand what is going on you can:

  1. configure event logs recording
  2. configure Remote Desktop Protocol to access the server
  3. Put a try catch around all the code in the OnStart method and record the exception in a database. You can easily do this using ELMAH
alexandrekow
  • 1,927
  • 2
  • 22
  • 40
  • My worker role is in the 'Ready' state.. so probably my code is not working somewhere but only when it's deployed to windows azure, in visual studio it does send mails – Yunieke May 16 '12 at 07:11
  • The best way to find out then is to use ELMAH – alexandrekow May 16 '12 at 08:47
0

Please Study my comments in the question below:

Webrole is not starting and always busy

For a worker role you dont need to follow step 2) above if you don't have a web server running, still you can all other steps to troubleshoot this issue.

Community
  • 1
  • 1
AvkashChauhan
  • 20,495
  • 3
  • 34
  • 65
  • yes I am sure that is the case. The code inside the role is not functioning due to some issue. When you RDP to your instance and you check if task is actually scheduled or not. You can also run some process monitor tool to see how your service is scheduled to send email.. – AvkashChauhan May 15 '12 at 18:06