コード例 #1
0
 /// <summary>
 /// Stop this service.
 /// </summary>
 protected override void OnStop()
 {
     lock (_lockObject)
     {
         if (_socket != null)
         {
             _socket.Stop();
             _socket = null;
         }
     }
     ServiceDebugger.WriteLogEntry(Name, "Stopping.");
 }
コード例 #2
0
        //private void StopThread()
        //{
        //    m_WorkerThread.Abort();
        //}

        private void WorkerThreadFunction()
        {
            try
            {
                lock (_lockObject)
                {
                    bool returnIdle = true;
                    ////bool.TryParse(ConfigurationManager.AppSettings["ReturnIdle"], out returnIdle);

                    Mode   mode    = Mode.Normal;
                    string modeStr = ConfigurationManager.AppSettings["Mode"];
                    mode = string.Equals(Mode.Drain.ToString(), modeStr, StringComparison.OrdinalIgnoreCase) ? Mode.Drain :
                           (string.Equals(Mode.Halt.ToString(), modeStr, StringComparison.OrdinalIgnoreCase) || string.Equals("down", modeStr, StringComparison.OrdinalIgnoreCase) ? Mode.Halt : Mode.Normal);

                    _socket = new SocketLib()
                    {
                        Alive = new Action <SocketLib>(socketLib =>
                        {
                            if (ReadRegKeyInt(RegKeyName, "AliveLogging", 0) > 0)
                            {
                                //Write to event log IF should
                                ServiceDebugger.WriteLogEntry(Name, String.Format("Listening on port {0}", socketLib.Port));
                            }
                        }),
                        Error = new Action <Exception>(exception =>
                        {
                            if (ReadRegKeyInt(RegKeyName, "ExceptionLogging", 0) > 0)
                            {
                                ServiceDebugger.WriteLogEntry(Name, exception.ToString());
                            }
                        }),
                        ReturnIdle = returnIdle,
                        Mode       = mode
                    };
                }
                _socket.Start();
            }
            catch (Exception ex)
            {
                ServiceDebugger.WriteLogEntry(Name, ex.ToString());
            }
            finally
            {
                //Tell OS we've stopped
                Stop();
            }
        }
コード例 #3
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
#if DEBUGSERVICE
            ServiceDebugger debug = new ServiceDebugger();
            debug.Service = new LBCPUMon();
            System.Windows.Forms.Application.Run(debug);
#else
            ServiceBase[] ServicesToRun;

            // More than one user Service may run within the same process. To add
            // another service to this process, change the following line to
            // create a second service object. For example,
            //
            //   ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
            //
            ServicesToRun = new ServiceBase[] { new LBCPUMon() };
#if DEBUG
            // Debugger.Launch();
#endif
            ServiceBase.Run(ServicesToRun);
#endif
        }