private void FinallyClose() { lock (this) { if (_Closed) { return; } _Closed = true; if (_Process != null) { try { if (!_Process.HasExited && _ILingvisticsProcessor != null) { Logger.InfoFormat("Proc({0}) start stopping", _Process.Id); try { var dtEnd = DateTime.Now.AddSeconds(Config.Default.ProcessorCloseTimeOutInSeconds); var t = new Thread(() => { try { _ILingvisticsProcessor.Close(); } catch { ; } } ); t.Start(); while (!_Process.HasExited && DateTime.Now < dtEnd) { Thread.Sleep(10); } } catch (Exception ex) { Logger.ErrorFormat("Proc({0}) error on stopping\n{1}", _Process.Id, ex.Message); } } if (!_Process.HasExited) { _Process.Kill(); Logger.InfoFormat("Proc({0}) force stopped", _Process.Id); } else { Logger.InfoFormat("Proc({0}) stopped", _Process.Id); } } catch (Exception ex) { Logger.ErrorFormat("Proc({0}) error on force stopped\n{1}", _Process.Id, ex.Message); } } _ILingvisticsProcessor = null; } }
public LingvisticsProcessor() { if (!File.Exists(ProcessorFilePath)) { throw (new Exception("ЕБАТЬ ВАШУ МАТЬ - '" + ProcessorFilePath + "' - НЕТ ТАКОГО ФАЙЛА")); } WindowsEvent startEvent = null; try { _Process = Process.Start( new ProcessStartInfo() { FileName = ProcessorFilePath, WorkingDirectory = ProcessorWorkingDirectory, Arguments = "LingvisticsServicePID=" + Process.GetCurrentProcess().Id, //"",//string.Format("{0} {1}", _port, _uri), CreateNoWindow = true, UseShellExecute = false } ); var url = string.Format("ipc://LP:{0}/{1}", _Process.Id, ProcessorUri); //ожидание запуска и сетевой инициализации процессора startEvent = new WindowsEvent(string.Format("LPStartEvent_{0}", _Process.Id)); while (!startEvent.Wait(10)) { if (_Process.HasExited) { throw (new ApplicationException(string.Format("Proc({0}) stopped", _Process.Id))); } } _ILingvisticsProcessor = (ILingvisticsProcessor)Activator.GetObject(typeof(ILingvisticsProcessor), url); } catch (Exception ex) { Logger.Error(ex.ToString()); throw (new ApplicationException("Error on start new proc")); } finally { if (startEvent != null) { startEvent.Close(); } } Logger.InfoFormat("New proc({0}) start", _Process.Id); }