Запуск службы внутри рабочей роли Azure

У меня есть служба Windows, которую мне нужно перенести в Azure в качестве рабочей роли. В моем решении Azure все работает нормально. Однако когда я загружаю все, запускается только веб-роль. Экземпляр рабочей роли застревает, циклически переходя между следующими двумя состояниями, но не запускается.

  • Ожидание запуска роли ...
  • Стабилизирующая роль ...

Поскольку экземпляр не запускается, я подозреваю, что у меня проблема лежит где-то в моем коде WorkerRole.cs. Ниже вы найдете этот код. Я также включил код службы на случай, если он имеет отношение к вопросу. Что я сделал не так?

Это мой файл WorkerRole.cs:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Threading;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;
using Microsoft.WindowsAzure.StorageClient;
using System.ServiceProcess;

namespace SBMWorker
{
public class WorkerRole : RoleEntryPoint
{

    public override void Run()
    {
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] 
        { 
            new Service1() 
        };
        ServiceBase.Run(ServicesToRun);

        //Thread.Sleep(Timeout.Infinite);
    }

}
}

Это мой код Service1.cs:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using Lesnikowski.Mail;

namespace SBMWorker

{
public partial class Service1 : ServiceBase
{
    private System.Timers.Timer mainTimer;

    public Service1()
    {
        InitializeComponent();
    }

    protected override void OnStart(string[] args)
    {
        try
        {
            // config the timer interval
            mainTimer = new System.Timers.Timer(foo.Framework.Configuration.SecondsToWaitBeforeCheckingForEmailsToProcess * 1000);
            // handling
            mainTimer.Elapsed += new System.Timers.ElapsedEventHandler(mainTimer_Elapsed);
            // startup the timer.  
            mainTimer.Start();
            // log that we started
            foo.Framework.Log.Add(foo.Framework.Log.Types.info, "SERVICE STARTED");
       }
        catch (Exception ex)
        {
            try
            {
                foo.Framework.Log.Add(ex, true);
            }
            catch{throw;}

            // make sure the throw this so the service show as stopped ... we dont want this service just hanging here like
            // its running, but really just doing nothing at all
            throw;
        }
    }

    protected override void OnStop()
    {
        if (mainTimer != null)
        {
            mainTimer.Stop();
            mainTimer = null;
        }
        // log that we stopped
        foo.Framework.Log.Add(foo.Framework.Log.Types.info, "SERVICE STOPPED"); 
    }

    void mainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        mainTimer.Stop();

        bool runCode = true;

        if (runCode)
        {
            try
            {
                // call processing
                foo.Framework.EmailPackageUpdating.ProcessEmails();
            }
            catch(Exception ex)
            {
                try
                {
                    // handle error 
                    foo.Framework.Log.Add(ex, false);
                }
                catch { throw; }
            }
        }

        mainTimer.Start();
    }
}
}
10
задан Athari 10 June 2014 в 09:45
поделиться