public virtual void KillProcess(Process p, bool gracefully = false) { Contract.Requires<ArgumentNullException>(p != null); if (gracefully) { p.CloseMainWindow(); var i = 0; while (!p.SafeHasExited()) { i++; if (i > 4) break; Thread.Sleep(1000); } } if (!p.SafeHasExited()) p.Kill(); }
public bool CheckZsyncLoop(Process process, string data, ITransferProgress progress) { // By not resetting the loopdata/counts we set ourselves up for a situation where it's possible to detect loops that span multiple lines.. if (!ZsyncLoop.IsMatch(data)) return false; if (progress.ZsyncLoopData == null) { progress.ZsyncLoopData = data; progress.ZsyncLoopCount = 0; return false; } if (progress.ZsyncLoopData.Equals(data, StringComparison.OrdinalIgnoreCase)) { var loopCount = ++progress.ZsyncLoopCount; if (loopCount < 2) return false; if (!process.SafeHasExited()) process.TryKill(); return true; } progress.ZsyncLoopData = data; progress.ZsyncLoopCount = 0; return false; }
static bool TryCheckHasExited(Process process) { try { return process.SafeHasExited(); } catch { return true; } }