} // StartSBComponents public bool StartSBProc(string i_sName, string i_sCmd, string i_sArgs) { bool bRet = true; SBProcess procChild = null; try { procChild = new SBProcess(); m_aProcs.Add(procChild); // Always add, even if it doesn't start because we may want to try again. procChild.Name = i_sName; procChild.Command = i_sCmd + " " + i_sArgs; procChild.Proc = new Process(); procChild.Proc.Exited += new EventHandler(proc_Exited); procChild.Proc.EnableRaisingEvents = true; //proc.SynchronizingObject = this; // Do we need to do this? Requires ISynchronizeInvoke //procChild.Proc.StartInfo.CreateNoWindow = true; //procChild.Proc.StartInfo.UseShellExecute = false; //procChild.Proc.StartInfo.WorkingDirectory = i_sWorkingDir; procChild.Proc.StartInfo.FileName = i_sCmd; procChild.Proc.StartInfo.Arguments = i_sArgs; bRet = procChild.Proc.Start(); if (!bRet) { m_Logger.Log(Level.Exception, "StartSBProc Failed to Start('" + i_sCmd + "', '" + i_sArgs + "')!"); } else { m_Logger.Log(Level.Info, "StartSBProc Start-ed('" + i_sCmd + "', '" + i_sArgs + "')."); } procChild.Running = bRet; } catch (Exception exc) { bRet = false; m_Logger.Log(Level.Exception, "StartSBProc tried to Start('" + i_sCmd + "', '" + i_sArgs + "'), caught exception: " + exc.ToString()); } return(bRet); } // StartSBProc
} // ResetSBComponents private void proc_Exited(object sender, System.EventArgs e) { int iPid = -1, ii = 0; SBProcess proc = null; bool bRes = true; string sFile = "", sArgs = "", sAMFile = "", sAMArgs = "", sDMFile = "", sDMArgs = ""; try { Monitor.Enter(m_aProcs); iPid = ((Process)sender).Id; for (ii = 0; ((ii < m_aProcs.Count) && (proc == null)); ii++) { if (m_aProcs[ii].Running) { if (m_aProcs[ii].Proc.Id == iPid) { proc = m_aProcs[ii]; m_aProcs.RemoveAt(ii); } } } if (proc == null) { m_Logger.Log(Level.Warning, "LRMWorkerThread.proc_Exited: PID '" + iPid.ToString() + "' not found in list! Reason: " + e.ToString()); } else { // AudioMgr and DialogMgr need to be restarted together, others are independent. if (proc.Proc.StartInfo.FileName.ToLower().IndexOf(m_csAppNameAudiomgr) > 0) { m_Logger.Log(Level.Warning, "LRMWorkerThread.proc_Exited: AudioMgr exited! Reason: " + e.ToString()); sAMFile = proc.Proc.StartInfo.FileName; sAMArgs = proc.Proc.StartInfo.Arguments; // Find DialogMgr and kill it (turning off events first.) // (Traverse entire list in case there are ligering copies running.) do { ii = FindComponentInProcessList(m_csAppNameDialogmgr, out sFile, out sArgs); if (ii != -1) { sDMFile = sFile; sDMArgs = sArgs; if (m_aProcs[ii].Running) // Only attempt to kill if it had been started { m_aProcs[ii].Proc.EnableRaisingEvents = false; m_aProcs[ii].Proc.Exited -= new EventHandler(proc_Exited); m_aProcs[ii].Proc.Kill(); } m_aProcs.RemoveAt(ii); } }while(ii != -1); // Start AudioMgr and DialogMgr back up. m_Logger.Log(Level.Info, "LRMWorkerThread.proc_Exited: Restarting AudioMgr & DialogMgr."); bRes = StartSBProc(m_csAppNameAudiomgr, sAMFile, sAMArgs); bRes = StartSBProc(m_csAppNameDialogmgr, sDMFile, sDMArgs); } else if (proc.Proc.StartInfo.FileName.ToLower().IndexOf(m_csAppNameDialogmgr) > 0) { m_Logger.Log(Level.Warning, "LRMWorkerThread.proc_Exited: DialogMgr exited! Reason: " + e.ToString()); sDMFile = proc.Proc.StartInfo.FileName; sDMArgs = proc.Proc.StartInfo.Arguments; // Find AudioMgr and kill it (turning off events first.) // (Traverse entire list in case there are ligering copies running.) do { ii = FindComponentInProcessList(m_csAppNameAudiomgr, out sFile, out sArgs); if (ii != -1) { sAMFile = sFile; sAMArgs = sArgs; if (m_aProcs[ii].Running) // Only attempt to kill if it had been started { m_aProcs[ii].Proc.EnableRaisingEvents = false; m_aProcs[ii].Proc.Exited -= new EventHandler(proc_Exited); m_aProcs[ii].Proc.Kill(); } m_aProcs.RemoveAt(ii); } }while(ii != -1); // Start AudioMgr and DialogMgr back up. m_Logger.Log(Level.Info, "LRMWorkerThread.proc_Exited: Restarting AudioMgr & DialogMgr."); bRes = StartSBProc(m_csAppNameAudiomgr, sAMFile, sAMArgs); bRes = StartSBProc(m_csAppNameDialogmgr, sDMFile, sDMArgs); } else { m_Logger.Log(Level.Warning, "LRMWorkerThread.proc_Exited: " + proc.Proc.StartInfo.FileName + " exited! Restarting it. (Args: '" + proc.Proc.StartInfo.Arguments + "') Reason: " + e.ToString()); bRes = StartSBProc(proc.Name, proc.Proc.StartInfo.FileName, proc.Proc.StartInfo.Arguments); } proc = null; } } catch (Exception exc) { m_Logger.Log(exc); } finally { Monitor.Exit(m_aProcs); } } // proc_Exited
public void Remove(SBProcess i_Elem) { List.Remove(i_Elem); }
public void Insert(int i_iIndex, SBProcess i_Elem) { List.Insert(i_iIndex, i_Elem); }
public int IndexOf(SBProcess i_Elem) { return(List.IndexOf(i_Elem)); }
public bool Contains(SBProcess i_Elem) { return(List.Contains(i_Elem)); }
public int Add(SBProcess i_Elem) { return(List.Add(i_Elem)); }