Example #1
0
        /// <summary>
        /// 开始监控
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btStart_Click(object sender, EventArgs e)
        {
            this.btStart.Enabled = false;
            this.btStop.Enabled  = true;
            if (this.cancellSource.IsCancellationRequested)
            {
                this.cancellSource = new CancellationTokenSource();
            }

            Task.Run(() =>
            {
                foreach (var item in DogConfig.GetConfigServiceNames())
                {
                    var control = new ServiceMonitor(item);
                    control.StartAsync(this.cancellSource.Token);
                }
            });

            Task.Run(() =>
            {
                foreach (var item in DogConfig.GetConfigProcessPaths())
                {
                    var control = new ProcessMonitor(item);
                    control.StartAsync(this.cancellSource.Token);
                }
            });
        }
Example #2
0
        /// <summary>
        /// 服务启动任务
        /// </summary>
        /// <param name="hostControl"></param>
        /// <returns></returns>
        public bool Start(HostControl hostControl)
        {
            Debugger.WriteLine("看门狗启动成功,开始监控!");
            //服务类监控
            foreach (var item in DogConfig.GetConfigServiceNames())
            {
                var monitor = new ServiceMonitor(item);
                monitor.StartAsync(this.cancellSource.Token);
            }

            //程序类监控
            foreach (var item in DogConfig.GetConfigProcessPaths())
            {
                var monitor = new ProcessMonitor(item);
                monitor.StartAsync(this.cancellSource.Token);
            }
            return(true);
        }