Last active
November 16, 2018 07:46
-
-
Save Criteo-dotnet-blog/7ee73b0e0947b3fc58044263abd66a64 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static SafeProcessHandle OpenProcess(int processId, int access, bool throwIfExited) | |
{ | |
SafeProcessHandle safeProcessHandle = NativeMethods.OpenProcess(access, false, processId); | |
int lastWin32Error = Marshal.GetLastWin32Error(); | |
if (!safeProcessHandle.IsInvalid) | |
return safeProcessHandle; | |
// error handling | |
if (processId == 0) | |
throw new Win32Exception(5); | |
if (ProcessManager.IsProcessRunning(processId)) | |
throw new Win32Exception(lastWin32Error); | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment