Bekommen eine Dienstleistung Ausführen, die in einer Azure Worker-Rolle

Ich habe einen windows-Dienst, den ich migrieren müssen, um auf Azure als Worker-Rolle. Alles baut feines in meinem Azure-Lösung. Allerdings, wenn ich laden Sie alles, was nur die web-Funktion wird gestartet. Die worker-Rolle Instanz stecken Radfahren zwischen den folgenden zwei Zustände, ohne jemals ab.

  • Zu warten, für die Rolle zu beginnen...
  • Stabilisierende Rolle...

Da die Instanz nicht starten, ich vermute mein problem liegt irgendwo in meinem WorkerRole.cs-code. Unten finden Sie diesen code. Ich habe das auch den code für den Dienst, falls es relevant für die Frage. Was habe ich falsch gemacht?

Dies ist mein WorkerRole.cs-Datei:

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);
    }

}
}

Dies ist mein Service1.cs-code:

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();
    }
}
}

InformationsquelleAutor der Frage hughesdan | 2011-08-11

Schreibe einen Kommentar