Пример #1
0
        private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            Data.SendToSystemLog(string.Format("Останов системы на станции {0}", Environment.MachineName));
            var dt = DateTime.Now + new TimeSpan(0, 0, 0, 1);

            while (dt > DateTime.Now)
            {
                Application.DoEvents();
            }
            //Код, выполняемый при остановке процесса
            try
            {
                if (_wcfEventService != null)
                {
                    _wcfEventService.Stop();
                }
            }
            catch (Exception ex)
            {
                Data.SendToErrorsLog("Ошибка при остановке локального сервера подписки: " + ex.FullMessage());
            }

            foreach (var worker in Workers.Where(worker => worker.IsBusy))
            {
                worker.CancelAsync();
            }
            dt = DateTime.Now + new TimeSpan(0, 0, 0, 1);
            while (dt > DateTime.Now)
            {
                Application.DoEvents();
            }
            _fileLogsWatcher.Changed -= fileSystemLogWatcher_Changed;
            _fileLogsWatcher.Created -= fileSystemLogWatcher_Changed;
            _fileLogsWatcher.Dispose();
            if (Data.RunningAsShell() || Data.MustWinLogOff)
            {
                WinLogOff();
            }
        }