-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessExtensions.cs
More file actions
26 lines (21 loc) · 911 Bytes
/
ProcessExtensions.cs
File metadata and controls
26 lines (21 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using DebugNET.PInvoke;
namespace System.Diagnostics {
public static class ProcessExtensions {
public static void Suspend(this Process process) {
foreach (ProcessThread thread in process.Threads) {
IntPtr handle = Kernel32.OpenThread(ThreadAccessFlags.SUSPEND_RESUME, false, thread.Id);
if (handle == IntPtr.Zero) continue;
Kernel32.SuspendThread(handle);
Kernel32.CloseHandle(handle);
}
}
public static void Resume(this Process process) {
foreach (ProcessThread thread in process.Threads) {
IntPtr handle = Kernel32.OpenThread(ThreadAccessFlags.SUSPEND_RESUME, false, thread.Id);
if (handle == IntPtr.Zero) continue;
Kernel32.ResumeThread(handle);
Kernel32.CloseHandle(handle);
}
}
}
}