public override object Run(bool wait) { try { Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(ThreadExceptionHandler); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(GlobalExceptionHandler); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); } catch { // Esto puede dar una excepción // "El modo de excepción del subproceso no se puede cambiar una vez que se creen Controles en el subproceso." // Simplemente la ignoramos. } Lbl.Sys.Config.Actual.UsuarioConectado = new Lbl.Sys.Configuracion.UsuarioConectado(new Lbl.Personas.Usuario(Lfx.Workspace.Master.MasterConnection, 1)); FormEstado = new Forms.Estado(); FormEstado.ServidorAsociado = this; try { using (System.Diagnostics.Process Yo = System.Diagnostics.Process.GetCurrentProcess()) { Yo.PriorityClass = System.Diagnostics.ProcessPriorityClass.High; } } catch (Exception Ex) { System.Console.WriteLine("ServidorFiscal: Imposible elevar la prioridad del proceso (" + Ex.ToString() + "). Continuando de todos modos."); //Seguramente no me permitió cambiar la prioridad por ser un usuario sin privilegios. //No es crítico, así que continúo sin problema } Impresora = new Lazaro.Impresion.Comprobantes.Fiscal.Impresora(Lfx.Workspace.Master); Lfx.Workspace.Master.RunTime.IpcEvent += new Lfx.RunTimeServices.IpcEventHandler(Componente_IpcEvent); Impresora.Notificacion += new Lazaro.Impresion.Comprobantes.Fiscal.NotificacionEventHandler(ConFiscal_EventoConexion); Programador = new System.Timers.Timer(1000); Programador.Elapsed += new System.Timers.ElapsedEventHandler(EventoProgramador); Programador.Start(); Watchdog = new System.Timers.Timer(60000); Watchdog.Elapsed += new System.Timers.ElapsedEventHandler(EventoWatchdog); Watchdog.Start(); if (wait) { while (Impresora.EstadoServidor != Lazaro.Impresion.Comprobantes.Fiscal.EstadoServidorFiscal.Apagando && Impresora.EstadoServidor != Lazaro.Impresion.Comprobantes.Fiscal.EstadoServidorFiscal.Reiniciando) { System.Threading.Thread.Sleep(100); System.Windows.Forms.Application.DoEvents(); } if (Impresora.EstadoServidor == Lazaro.Impresion.Comprobantes.Fiscal.EstadoServidorFiscal.Reiniciando) { this.End(true); } else if (Impresora.EstadoServidor == Lazaro.Impresion.Comprobantes.Fiscal.EstadoServidorFiscal.Apagando) { this.End(false); } } return(null); }
public override object Run(bool wait) { try { Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(ThreadExceptionHandler); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(GlobalExceptionHandler); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); } catch { // Esto puede dar una excepción // "El modo de excepción del subproceso no se puede cambiar una vez que se creen Controles en el subproceso." // Simplemente la ignoramos. } Lbl.Sys.Config.Actual.UsuarioConectado = new Lbl.Sys.Configuracion.UsuarioConectado(new Lbl.Personas.Usuario(Lfx.Workspace.Master.MasterConnection, 1)); FormEstado = new Forms.Estado(); FormEstado.ServidorAsociado = this; try { using (System.Diagnostics.Process Yo = System.Diagnostics.Process.GetCurrentProcess()) { Yo.PriorityClass = System.Diagnostics.ProcessPriorityClass.High; } } catch (Exception Ex) { System.Console.WriteLine("ServidorFiscal: Imposible elevar la prioridad del proceso (" + Ex.ToString() + "). Continuando de todos modos."); //Seguramente no me permitió cambiar la prioridad por ser un usuario sin privilegios. //No es crítico, así que continúo sin problema } Impresora = new Lazaro.Impresion.Comprobantes.Fiscal.Impresora(Lfx.Workspace.Master); Lfx.Workspace.Master.RunTime.IpcEvent += new Lfx.RunTimeServices.IpcEventHandler(Componente_IpcEvent); Impresora.Notificacion += new Lazaro.Impresion.Comprobantes.Fiscal.NotificacionEventHandler(ConFiscal_EventoConexion); Programador = new System.Timers.Timer(1000); Programador.Elapsed += new System.Timers.ElapsedEventHandler(EventoProgramador); Programador.Start(); Watchdog = new System.Timers.Timer(60000); Watchdog.Elapsed += new System.Timers.ElapsedEventHandler(EventoWatchdog); Watchdog.Start(); if (wait) { while (Impresora.EstadoServidor != Lazaro.Impresion.Comprobantes.Fiscal.EstadoServidorFiscal.Apagando && Impresora.EstadoServidor != Lazaro.Impresion.Comprobantes.Fiscal.EstadoServidorFiscal.Reiniciando) { System.Threading.Thread.Sleep(100); System.Windows.Forms.Application.DoEvents(); } if (Impresora.EstadoServidor == Lazaro.Impresion.Comprobantes.Fiscal.EstadoServidorFiscal.Reiniciando) this.End(true); else if (Impresora.EstadoServidor == Lazaro.Impresion.Comprobantes.Fiscal.EstadoServidorFiscal.Apagando) this.End(false); } return null; }