Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ OpenProcess()

static SafeProcessHandle System.Diagnostics.ProcessManager.OpenProcess ( int processId,
int access,
bool throwIfExited )
inlinestatic

Definition at line 133 of file ProcessManager.cs.

134 {
135 SafeProcessHandle safeProcessHandle = global::Interop.Kernel32.OpenProcess(access, inherit: false, processId);
136 int lastWin32Error = Marshal.GetLastWin32Error();
137 if (!safeProcessHandle.IsInvalid)
138 {
139 return safeProcessHandle;
140 }
141 if (processId == 0)
142 {
143 throw new Win32Exception(5);
144 }
145 if (lastWin32Error != 5 && !IsProcessRunning(processId))
146 {
147 if (throwIfExited)
148 {
149 throw new InvalidOperationException(System.SR.Format(System.SR.ProcessHasExited, processId.ToString()));
150 }
152 }
153 throw new Win32Exception(lastWin32Error);
154 }
static readonly SafeProcessHandle InvalidHandle
static bool IsProcessRunning(int processId)
static string ProcessHasExited
Definition SR.cs:32
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7

References System.SR.Format(), System.Runtime.InteropServices.Marshal.GetLastWin32Error(), Microsoft.Win32.SafeHandles.SafeProcessHandle.InvalidHandle, Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid.IsInvalid, System.Diagnostics.ProcessManager.IsProcessRunning(), and System.SR.ProcessHasExited.

Referenced by System.Diagnostics.NtProcessManager.GetModules(), and System.Diagnostics.Process.GetProcessHandle().