public void TerminateNewChildsAsync(int nDelayMs) { List <uint> lPids = GetChildPids(); foreach (uint uPid in lPids) { if (m_lPids.IndexOf(uPid) < 0) { CpsTermInfo ti = new CpsTermInfo(uPid, m_strChildExeName, nDelayMs); ParameterizedThreadStart pts = new ParameterizedThreadStart( ChildProcessesSnapshot.DelayedTerminatePid); Thread th = new Thread(pts); th.Start(ti); } } }
public void TerminateNewChildsAsync(int nDelayMs) { List<uint> lPids = GetChildPids(); foreach(uint uPid in lPids) { if(m_lPids.IndexOf(uPid) < 0) { CpsTermInfo ti = new CpsTermInfo(uPid, m_strChildExeName, nDelayMs); ParameterizedThreadStart pts = new ParameterizedThreadStart( ChildProcessesSnapshot.DelayedTerminatePid); Thread th = new Thread(pts); th.Start(ti); } } }
private static void DelayedTerminatePid(object oTermInfo) { try { CpsTermInfo ti = (oTermInfo as CpsTermInfo); if (ti == null) { Debug.Assert(false); return; } if (ti.Delay > 0) { Thread.Sleep(ti.Delay); } Process p = Process.GetProcessById((int)ti.ProcessId); if (p == null) { Debug.Assert(false); return; } // Verify that likely it's indeed the correct process if (!string.IsNullOrEmpty(ti.ExeName)) { string str = GetExeName(p.MainModule.FileName); if (!str.Equals(ti.ExeName, StrUtil.CaseIgnoreCmp)) { Debug.Assert(false); return; } } p.Kill(); p.Close(); } catch (ArgumentException) { } // Not running catch (Exception) { Debug.Assert(false); } }