public Job() { handle = CreateJobObject(IntPtr.Zero, null); var info = new JOBOBJECT_BASIC_LIMIT_INFORMATION { LimitFlags = (uint)LimitFlags.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE }; var io = new IO_COUNTERS { OtherOperationCount = 0, OtherTransferCount = 0, ReadOperationCount = 0, ReadTransferCount = 0, WriteOperationCount = 0, WriteTransferCount = 0 }; var extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION { BasicLimitInformation = info }; int length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION)); IntPtr extendedInfoPtr = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false); if (!SetInformationJobObject(handle, JobObjectInfoType.ExtendedLimitInformation, extendedInfoPtr, (uint)length)) { throw new Exception(string.Format("Job object: Unable to set information. Error: {0}", Marshal.GetLastWin32Error())); } }
public Job() { handle = CreateJobObject(IntPtr.Zero, null); var info = new JOBOBJECT_BASIC_LIMIT_INFORMATION { LimitFlags = (uint)LimitFlags.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE }; var io = new IO_COUNTERS { OtherOperationCount = 0, OtherTransferCount = 0, ReadOperationCount = 0, ReadTransferCount = 0, WriteOperationCount = 0, WriteTransferCount = 0 }; var extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION { BasicLimitInformation = info }; int length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION)); IntPtr extendedInfoPtr = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false); if (!SetInformationJobObject(handle, JobObjectInfoType.ExtendedLimitInformation, extendedInfoPtr, (uint)length)) throw new Exception(string.Format("Job object: Unable to set information. Error: {0}", Marshal.GetLastWin32Error())); }