Beispiel #1
0
        // Start the service.
        protected override void OnStart(string[] args)
        {
            try
            {
                var handle = ServiceHandle;
                _myServiceStatus.currentState = (int)State.SERVICE_START_PENDING;
                SetServiceStatus(handle, _myServiceStatus);

                // Start a separate thread that does the actual work.
                if ((_workerThread == null) || ((_workerThread.ThreadState & (ThreadState.Unstarted | ThreadState.Stopped)) != 0))
                {
                    Logger.Log.Info("-=START=-");
                    // Build status info
                    var statusInfo = string.Format(@"
                        <html>MODE: <font size='3' color='red'>{0}</font><br>
                            VERSION: <font size='3' color='red'>{1}</font>
                        </html>", Config.Mode, Assembly.GetEntryAssembly().GetName().Version);
                    Zabbix.Sender.SendData(new ZabbixItem {
                        Host = Config.HostKey, Key = Config.StatusKey, Value = statusInfo
                    });

                    _mailWorker   = new MailWorker();
                    _workerThread = new Thread(_mailWorker.Worker);
                    _workerThread.Start();
                }
                if (_workerThread != null)
                {
                    Logger.Log.Debug("Worker thread state = {0}", _workerThread.ThreadState.ToString());
                }

                _myServiceStatus.currentState = (int)State.SERVICE_RUNNING;
                SetServiceStatus(handle, _myServiceStatus);
            }
            catch (Exception ex)
            {
                Logger.Log.Error("Error on start: {0}", ex.Message);
            }
        }
Beispiel #2
0
        // Start the service.
        protected override void OnStart(string[] args)
        {
            try
            {
                var handle = ServiceHandle;
                _myServiceStatus.currentState = (int)State.SERVICE_START_PENDING;
                SetServiceStatus(handle, _myServiceStatus);

                // Start a separate thread that does the actual work.
                if ((_workerThread == null) || ((_workerThread.ThreadState & (ThreadState.Unstarted | ThreadState.Stopped)) != 0))
                {
                    Logger.Log.Info("-=START=-");
                    // Build status info
                    var statusInfo = string.Format(@"
                        <html>MODE: <font size='3' color='red'>{0}</font><br>
                            VERSION: <font size='3' color='red'>{1}</font>
                        </html>", Config.Mode, Assembly.GetEntryAssembly().GetName().Version);
                    Zabbix.Sender.SendData(new ZabbixItem { Host = Config.HostKey, Key = Config.StatusKey, Value = statusInfo });

                    _mailWorker = new MailWorker();
                    _workerThread = new Thread(_mailWorker.Worker);
                    _workerThread.Start();
                }
                if (_workerThread != null)
                    Logger.Log.Debug("Worker thread state = {0}", _workerThread.ThreadState.ToString());

                _myServiceStatus.currentState = (int)State.SERVICE_RUNNING;
                SetServiceStatus(handle, _myServiceStatus);
            }
            catch (Exception ex)
            {
                Logger.Log.Error("Error on start: {0}", ex.Message);
            }
        }