Exemplo n.º 1
0
        private void CompleteStop()
        {
            try
            {
                LogPacketEvent  = null;
                EditPacketEvent = null;

                lock (_subServices)
                {
                    foreach (ProxyNetworkService subService in _subServices)
                    {
                        subService.CompleteStop();
                    }
                    _subServices.Clear();
                }

                CloseConnectionEvent = null;
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
            }
            finally
            {
                _state = (int)ServiceState.Stopped;
                ServiceStoppedEvent?.Invoke(this, new EventArgs());
                ServiceStoppedEvent = null;
            }
        }
        private Task ServiceStopHandlerOnServiceStoppedEvent(ServiceStoppedEvent arg)
        {
            if (arg.ServiceName == _targetService)
            {
                _manualReset.Set();
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 3
0
        public void Run(string[] args)
        {
            if (IsService)
            {
                Log.Info($"{nameof(Run)}: It's a service, using the ServiceBase");
                var services = new ServiceBase[] { this };
                ServiceBase.Run(services);
                return;
            }

            Log.Info($"{nameof(Run)}: Not a service. Firing {nameof(OnStart)}");
            OnStart(args);

            if (!ConsoleUtils.TryWaitForKey())
            {
                Log.Info($"{nameof(Run)}: There's NO console window, waiting for the service to end.");
                try {
                    ServiceStoppedEvent.WaitOne();
                } catch (ObjectDisposedException) { }
            }
        }