public override void Stop() { try { //_serverExtensions.StopServices(); IntentionalStop = true; if (!proc.HasExited) { proc.Kill(); } m_active = false; ProcMonitor.StopMonitor(); } catch { Trace.WriteLine("CRITICAL ERROR! *** Exception while stopping server process!"); } }
public void StartNewProcess() { // Create a new process object proc = new System.Diagnostics.Process(); // Check and see if the previously logged process is still running bool pickupProcess = false; if (File.Exists(_startupFolder + "\\proclog")) { StreamReader sr = new StreamReader(new FileStream(_startupFolder + "\\proclog", FileMode.Open)); int procID = Convert.ToInt32(sr.ReadLine()); string windowTitle = sr.ReadLine(); sr.Close(); // Check for a process match try { Process tempProcess = Process.GetProcessById(procID); if (!((object)tempProcess == null)) { // Verify the window title if (tempProcess.MainWindowTitle == windowTitle) { // Yep - process is still running Trace.WriteLine("Picked up on previous process."); pickupProcess = true; proc = tempProcess; } } } catch { // Process must not exist pickupProcess = false; } } if (!pickupProcess) { proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = _startupFolder + "\\" + _commandLine; proc.StartInfo.WorkingDirectory = _startupFolder; proc.StartInfo.Arguments = _parameters; proc.Start(); System.Threading.Thread.Sleep(1000); // Log the process if (File.Exists(_startupFolder + "\\proclog")) { File.Delete(_startupFolder + "\\proclog"); } StreamWriter sw = new StreamWriter(new FileStream(_startupFolder + "\\proclog", FileMode.Create)); sw.WriteLine(proc.Id); sw.WriteLine(proc.MainWindowTitle); sw.Close(); Trace.WriteLine("Window Handle: " + proc.MainWindowHandle); Trace.WriteLine("Window Title: " + proc.MainWindowTitle); } // Bind the monitor to this process and start it ProcMonitor.BindToProcess(ref proc); ProcMonitor.StartMonitor(); // Start the delagginator //delag = new Delagginator(proc.Id); //delag.Delaggit(); }