コード例 #1
0
 protected override void OnStop()
 {
     try
     {
         EventLog.WriteEntry("TPVCOFO System Monitor Stop.");
         ServiceLogTPVCOFO.Instance.WriteLine("Stop Servicio : ", true);
         _serviceThread.Stop("Stoped");
         ServiceLogTPVCOFO.Instance.GrabarLog();
         //_paused = true;
     }
     catch (Exception ex)
     {
         if (ex.InnerException != null)
         {
             ServiceLogTPVCOFO.Instance.WriteLine("Stoped Error :" + ex.InnerException.Message, true);
         }
         else
         {
             ServiceLogTPVCOFO.Instance.WriteLine("Stoped Error :" + ex.Message, true);
         }
         ServiceLogTPVCOFO.Instance.GrabarLog();
     }
 }
コード例 #2
0
        //private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
        //{
        //    if (e.Mode == PowerModes.Suspend)
        //    {

        //        File.AppendAllLines(@"C:\prueba.txt", new string[] { "Supendido" }, Encoding.ASCII);
        //    }
        //    else
        //    {
        //        File.AppendAllLines(@"C:\prueba.txt", new string[] { "Reanudado" }, Encoding.ASCII);
        //    }

        //}

        protected override bool OnPowerEvent(PowerBroadcastStatus powerstatus)
        {
            _serviceThread = new ServiceThreadTPVCOFO();
            if (powerstatus == PowerBroadcastStatus.Suspend)
            {
                //Proceso p = Process.Start("shutdown.exe", "/ r");
                //p.WaitForExit();
                //File.AppendAllLines(@"C:\prueba.txt", new string[] { "Supendido - OnPowerEvent" }, Encoding.ASCII);
                EventLog.WriteEntry("Supensión de Equipo - Servicio de Windows");
                ServiceLogTPVCOFO.Instance.WriteLine("***********Supensión de Equipo - Servicio de Windows***********", true);
                _serviceThread.Stop("Stoped");
            }
            else if (powerstatus == PowerBroadcastStatus.ResumeSuspend)
            {
                //File.AppendAllLines(@"C:\prueba.txt", new string[] { "Reanudado - OnPowerEvent" }, Encoding.ASCII);
                EventLog.WriteEntry("Reanudado de Equipo - Servicio de Windows");
                ServiceLogTPVCOFO.Instance.WriteLine("***********Reanudado de Equipo - Servicio de Windows***********", true);
                _serviceThread.Start("Started");
            }
            return(base.OnPowerEvent(powerstatus));
        }