Exemplo n.º 1
0
 public JobObject()
 {
     this.jobHandle = NativeMethods.CreateJobObject(IntPtr.Zero, null);
     NativeMethods.JobObjectExtendedLimitInformation info = new NativeMethods.JobObjectExtendedLimitInformation();
     info.LimitFlags = NativeMethods.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
     if (!NativeMethods.SetInformationJobObject(this.jobHandle, NativeMethods.JobObjectExtendedLimitInformationClass, ref info, Marshal.SizeOf(info)))
     {
         int error = Marshal.GetLastWin32Error();
         TraceHelper.TraceEvent(TraceEventType.Error, "[JobObject] Failed to set information to job object: ErrorCode = {0}", error);
         throw new Win32Exception(error);
     }
 }
Exemplo n.º 2
0
        private void SetJobLimits(NativeMethods.JobObjectExtendedLimitInformation extendedLimit)
        {
            int    length          = Marshal.SizeOf(typeof(NativeMethods.JobObjectExtendedLimitInformation));
            IntPtr extendedInfoPtr = IntPtr.Zero;

            try
            {
                extendedInfoPtr = Marshal.AllocHGlobal(length);

                Marshal.StructureToPtr(extendedLimit, extendedInfoPtr, false);

                if (!NativeMethods.SetInformationJobObject(handle, NativeMethods.JobObjectInfoClass.ExtendedLimitInformation, extendedInfoPtr, length))
                {
                    throw new Exception(string.Format("Unable to set information.  Error: {0}", Marshal.GetLastWin32Error()));
                }
            }
            finally
            {
                if (extendedInfoPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(extendedInfoPtr);
                }
            }
        }