internal void CheckJobStatus(object stateInfo) { AutoResetEvent autoResetEvent = (AutoResetEvent)stateInfo; JOBOBJECT_BASIC_PROCESS_ID_LIST jOBOBJECTBASICPROCESSIDLIST = new JOBOBJECT_BASIC_PROCESS_ID_LIST(); int num = Marshal.SizeOf(jOBOBJECTBASICPROCESSIDLIST); if (NativeMethods.QueryInformationJobObject(this.jobObjectHandle, 3, ref jOBOBJECTBASICPROCESSIDLIST, num, IntPtr.Zero) && jOBOBJECTBASICPROCESSIDLIST.NumberOfAssignedProcess == 0) { autoResetEvent.Set(); } }
public static extern bool QueryInformationJobObject(SafeHandle hJob, int JobObjectInfoClass, ref JOBOBJECT_BASIC_PROCESS_ID_LIST lpJobObjectInfo, int cbJobObjectLength, IntPtr lpReturnLength);
/// <summary> /// Checks to see if the JobObject is empty (has no assigned processes). /// If job is empty the auto reset event supplied as input would be set. /// </summary> internal void CheckJobStatus(Object stateInfo) { ManualResetEvent emptyJobAutoEvent = (ManualResetEvent)stateInfo; int dwSize = 0; const int JOB_OBJECT_BASIC_PROCESS_ID_LIST = 3; JOBOBJECT_BASIC_PROCESS_ID_LIST JobList = new JOBOBJECT_BASIC_PROCESS_ID_LIST(); dwSize = Marshal.SizeOf(JobList); if (NativeMethods.QueryInformationJobObject(_jobObjectHandle, JOB_OBJECT_BASIC_PROCESS_ID_LIST, ref JobList, dwSize, IntPtr.Zero)) { if (JobList.NumberOfAssignedProcess == 0) { emptyJobAutoEvent.Set(); } } }
public static extern bool QueryInformationJobObject(SafeHandle hJob, int JobObjectInfoClass, ref JOBOBJECT_BASIC_PROCESS_ID_LIST lpJobObjectInfo, int cbJobObjectLength, IntPtr lpReturnLength);