public static JobObject Attach(string jobObjectName) { if (string.IsNullOrEmpty(jobObjectName)) { throw new ArgumentNullException("jobObjectName"); } JobObjectHandle jobHandle = null; JobObject result = null; JobObject tempResult = null; try { // JOB_OBJECT_ALL_ACCESS = 0x1F001F jobHandle = NativeMethods.OpenJobObject(0x1F001F, false, jobObjectName); if (jobHandle.IsInvalid) { int error = Marshal.GetLastWin32Error(); throw new Win32Exception(error, "Failed to open job object."); } tempResult = new JobObject(jobHandle, jobObjectName); jobHandle = null; result = tempResult; tempResult = null; } finally { if (jobHandle != null) { jobHandle.Dispose(); } if (tempResult != null) { tempResult.Dispose(); } } return(result); }
public static JobObject Attach(string jobObjectName) { if (string.IsNullOrEmpty(jobObjectName)) { throw new ArgumentNullException("jobObjectName"); } JobObjectHandle jobHandle = null; JobObject result = null; JobObject tempResult = null; try { // JOB_OBJECT_ALL_ACCESS = 0x1F001F jobHandle = NativeMethods.OpenJobObject(0x1F001F, false, jobObjectName); if (jobHandle.IsInvalid) { int error = Marshal.GetLastWin32Error(); throw new Win32Exception(error, "Failed to open job object."); } tempResult = new JobObject(jobHandle, jobObjectName); jobHandle = null; result = tempResult; tempResult = null; } finally { if (jobHandle != null) { jobHandle.Dispose(); } if (tempResult != null) { tempResult.Dispose(); } } return result; }