Пример #1
0
        protected bool StartService()
        {
            try
            {
                if (_windowsServiceMonitor == null)
                {
                    return(false);
                }

                if (!ServiceRunning())
                {
                    _windowsServiceMonitor.Start();
                    InitialServiceStatus();
                    MessageBox.Show("开启采集服务成功!");
                    return(true);
                }
                else
                {
                    InitialServiceStatus();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return(false);
            }
        }
Пример #2
0
        private async Task ChangeServiceStatus(object context)
        {
            ReadyToChange = false;
            try
            {
                if (_serviceMonitor.IsRunning)
                {
                    await _serviceMonitor.Stop();
                }
                else
                {
                    await _serviceMonitor.Start();
                }
            }
            catch (Exception ex)
            {
                ReadyToChange = true;
                throw new Exception("Could not do that", ex);
                // UserMessages.Text = ex.InnerException.Message;
            }

            Running = _serviceMonitor.IsRunning;
            ReadyToChange = true;
        }