forked from n00mkrad/flowframes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added pausing/resuming for interpolation, async (background) web checks
- Loading branch information
Showing
17 changed files
with
332 additions
and
46 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Win32Interop; | ||
|
||
namespace Flowframes.Extensions | ||
{ | ||
public static class ProcessExtensions | ||
{ | ||
[Flags] | ||
public enum ThreadAccess : int | ||
{ | ||
TERMINATE = (0x0001), | ||
SUSPEND_RESUME = (0x0002), | ||
GET_CONTEXT = (0x0008), | ||
SET_CONTEXT = (0x0010), | ||
SET_INFORMATION = (0x0020), | ||
QUERY_INFORMATION = (0x0040), | ||
SET_THREAD_TOKEN = (0x0080), | ||
IMPERSONATE = (0x0100), | ||
DIRECT_IMPERSONATION = (0x0200) | ||
} | ||
|
||
[DllImport("kernel32.dll")] | ||
static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId); | ||
[DllImport("kernel32.dll")] | ||
static extern uint SuspendThread(IntPtr hThread); | ||
[DllImport("kernel32.dll")] | ||
static extern int ResumeThread(IntPtr hThread); | ||
|
||
public static void Suspend(this Process process) | ||
{ | ||
foreach (ProcessThread thread in process.Threads) | ||
{ | ||
var pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)thread.Id); | ||
|
||
if (pOpenThread == IntPtr.Zero) | ||
break; | ||
|
||
SuspendThread(pOpenThread); | ||
} | ||
} | ||
|
||
public static void Resume(this Process process) | ||
{ | ||
foreach (ProcessThread thread in process.Threads) | ||
{ | ||
var pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)thread.Id); | ||
|
||
if (pOpenThread == IntPtr.Zero) | ||
break; | ||
|
||
ResumeThread(pOpenThread); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.