Skip to content

Commit 6ed6d61

Browse files
committed
better exception handling in registry states
1 parent 4a8f999 commit 6ed6d61

2 files changed

Lines changed: 118 additions & 192 deletions

File tree

FlashpointSecurePlayer/ProcessSync.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ public static void Start(Process process = null) {
106106
return;
107107
}
108108

109+
IntPtr processHandle = IntPtr.Zero;
110+
111+
if (process == null) {
112+
using (process = Process.GetCurrentProcess()) {
113+
processHandle = process.Handle;
114+
}
115+
} else {
116+
processHandle = process.Handle;
117+
}
118+
119+
if (processHandle == IntPtr.Zero) {
120+
throw new JobObjectException("Could not get the Process.");
121+
}
122+
109123
if (jobHandle == IntPtr.Zero) {
110124
jobHandle = CreateJobObject(IntPtr.Zero, null);
111125

@@ -128,20 +142,12 @@ public static void Start(Process process = null) {
128142
try {
129143
Marshal.StructureToPtr(jobobjectExtendedLimitInformation, jobobjectExtendedLimitInformationPointer, false);
130144

131-
bool result = SetInformationJobObject(jobHandle, JOBOBJECTINFOCLASS.JobObjectExtendedLimitInformation, jobobjectExtendedLimitInformationPointer, (uint)jobobjectExtendedLimitInformationSize);
132-
133-
IntPtr processHandle = IntPtr.Zero;
134-
135-
if (process == null) {
136-
using (process = Process.GetCurrentProcess()) {
137-
processHandle = process.Handle;
138-
}
139-
} else {
140-
processHandle = process.Handle;
145+
if (!SetInformationJobObject(jobHandle, JOBOBJECTINFOCLASS.JobObjectExtendedLimitInformation, jobobjectExtendedLimitInformationPointer, (uint)jobobjectExtendedLimitInformationSize)) {
146+
throw new JobObjectException("Could not set the Job Object Information.");
141147
}
142148

143-
if (!result || !AssignProcessToJobObject(jobHandle, processHandle)) {
144-
throw new JobObjectException("Could not set the Job Object Information or assign the Process to the Job Object.");
149+
if (!AssignProcessToJobObject(jobHandle, processHandle)) {
150+
throw new JobObjectException("Could assign the Process to the Job Object.");
145151
}
146152

147153
Started = true;

0 commit comments

Comments
 (0)