Escribí un servicio de Windows en C# que básicamente verifica mi DN cada minuto para pedidos, genera un PDF a partir de estos pedidos y lo envía por correo electrónico.Error 1053 el servicio no respondió a la solicitud de inicio o control
La lógica funciona perfectamente en mis pruebas, etc ..
cuando se crea el servicio, e instalarlo mediante el proyecto de instalación, cuando voy a iniciar el servicio en el MMC de servicios, me sale:
el error 1053 el servicio no respondió a la solicitud de inicio o control de una forma oportuna
Mi método OnStart se ve así:
protected override void OnStart(string[] args)
{
//writeToWindowsEventLog("Service started", EventLogEntryType.Information);
timer.Enabled = true;
}
Básicamente, solo habilita el temporizador ... por lo que no hay llamadas intensivas de proceso allí.
¿Dónde me estoy equivocando?
He intentado configurar la cuenta de inicio para el sistema local, el servicio de red, etc ... ¡nada funciona!
Editar:
Aquí está mi código: (processPurchaseOrders es el método en el que se consulta la base de datos y archivos PDF se generan etc ...)
public partial class PurchaseOrderDispatcher : ServiceBase
{
//this is the main timer of the service
private System.Timers.Timer timer;
public PurchaseOrderDispatcher()
{
InitializeComponent();
}
// The main entry point for the process
static void Main()
{
#if (!DEBUG)
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new PurchaseOrderDispatcher() };
ServiceBase.Run(ServicesToRun);
#else //debug code
PurchaseOrderDispatcher service = new PurchaseOrderDispatcher();
service.processPurchaseOrders();
#endif
}
private void InitializeComponent()
{
this.CanPauseAndContinue = true;
this.ServiceName = "Crocus_PurchaseOrderGenerator";
}
private void InitTimer()
{
timer = new System.Timers.Timer();
//wire up the timer event
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
//set timer interval
var timeInSeconds = Convert.ToInt32(ConfigurationManager.AppSettings["TimerIntervalInSeconds"]);
timer.Interval = (timeInSeconds * 1000); // timer.Interval is in milliseconds, so times above by 1000
timer.Enabled = true;
}
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
components.Dispose();
base.Dispose(disposing);
}
protected override void OnStart(string[] args)
{
//instantiate timer
Thread t = new Thread(new ThreadStart(this.InitTimer));
t.Start();
}
protected override void OnStop()
{
//turn off the timer.
timer.Enabled = false;
}
protected override void OnPause()
{
timer.Enabled = false;
base.OnPause();
}
protected override void OnContinue()
{
timer.Enabled = true;
base.OnContinue();
}
protected void timer_Elapsed(object sender, ElapsedEventArgs e)
{
processPurchaseOrders();
}
}
¿Qué hay en su constructor sin embargo? El problema podría estar allí. –
todo lo que tengo en mi contstructor es this.CanPauseAndContinue = true; this.ServiceName = "Crocus_PurchaseOrderGenerator"; – Alex
¿Dónde instancia el temporizador? Eche un vistazo al ejemplo que publiqué a continuación (http://clifgriffin.com/2008/11/20/using-timers-in-ac-windows-service/) sobre cómo configurar el temporizador en un servicio de Windows – SwDevMan81