public static Finally SuspendProcess(Process process) { var suspendedThreads = new HashSet <IntPtr>(); foreach (ProcessThread thread in process.Threads) { var hThread = Win32.OpenThread(ThreadAccessFlags.SuspendResume, false, thread.Id); if (hThread != IntPtr.Zero) { suspendedThreads.Add(hThread); Win32.SuspendThread(hThread); } else { Console.WriteLine("Could not open thread {0}", thread.Id); } } return(Finally.Do(() => { foreach (IntPtr hThread in suspendedThreads) { Win32.ResumeThread(hThread); Win32.CloseHandle(hThread); } })); }