예제 #1
0
        /// <summary>
        /// Updates the CPU rate limit associated with the job.
        /// </summary>
        /// <param name="value">The limit in total CPU percent.</param>
        public void UpdateCpuRateLimit(double value)
        {
            var cpuRateInfo = new JOBOBJECT_CPU_RATE_CONTROL_INFORMATION
            {
                ControlFlags = 1 | 4,
                CpuRate      = (uint)(value * 100)
            };
            var    length         = Marshal.SizeOf(typeof(JOBOBJECT_CPU_RATE_CONTROL_INFORMATION));
            IntPtr cpuRateInfoPtr = Marshal.AllocHGlobal(length);

            Marshal.StructureToPtr(cpuRateInfo, cpuRateInfoPtr, false);
            if (!SetInformationJobObject(handle, JobObjectInfoType.JobObjectCpuRateControlInformation, cpuRateInfoPtr, (uint)length))
            {
                Marshal.FreeHGlobal(cpuRateInfoPtr);
                throw new Exception(string.Format("Unable to set cpu rate information.  Error: {0}", Marshal.GetLastWin32Error()));
            }
            Marshal.FreeHGlobal(cpuRateInfoPtr);
        }
예제 #2
0
        /// <summary>
        /// Updates the CPU rate limit associated with the job.
        /// </summary>
        /// <param name="value">The limit in total CPU percent.</param>
        public void UpdateCpuRateLimit(double value)
        {
            var cpuRateInfo = new JOBOBJECT_CPU_RATE_CONTROL_INFORMATION
            {
                ControlFlags = 1 | 4,
                CpuRate = (uint)(value * 100)
            };
            var length = Marshal.SizeOf(typeof(JOBOBJECT_CPU_RATE_CONTROL_INFORMATION));
            IntPtr cpuRateInfoPtr = Marshal.AllocHGlobal(length);
            Marshal.StructureToPtr(cpuRateInfo, cpuRateInfoPtr, false);
            if (!SetInformationJobObject(handle, JobObjectInfoType.JobObjectCpuRateControlInformation, cpuRateInfoPtr, (uint)length))
            {
                Marshal.FreeHGlobal(cpuRateInfoPtr);
                throw new Exception(string.Format("Unable to set cpu rate information.  Error: {0}", Marshal.GetLastWin32Error()));

            }
            Marshal.FreeHGlobal(cpuRateInfoPtr);

        }