示例#1
0
        protected override void OnStart(string[] args)
        {
            //Se encarga de llamar al timer con el intervalo ingresado por parametro
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = tiempo; // cantidad desde app.config
            timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer);
            timer.Start();

            // Actualiar estado del inicio pendiente.
            ServiceStatus serviceStatus = new ServiceStatus();

            serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
            serviceStatus.dwWaitHint     = 100000;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);

            // Actualizar el estado del servicio en ejecución.
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);

            try
            {
                contexto cn       = new contexto();
                string   servidor = cn.getConexion();

                eventLogRegistro.WriteEntry("Conectado correctamente a la base de datos.", EventLogEntryType.Information, eventRegistroId++);
                eventLogRegistro.WriteEntry("Tiempo establecido para envio de correos: " + tiempo + " milisegundos.", EventLogEntryType.Information, eventRegistroId++);
            }
            catch (Exception e)
            {
                eventLogRegistro.WriteEntry("Error al conectar con la base de datos " + e.Message, EventLogEntryType.Information, eventRegistroId++);
                OnStop();
            }
        }