private void btnTest_Click(object sender, EventArgs e) { double f = 59.26535897936; string r = FmtFloat(f); return; uint cpuThrottleMax = 5; uint ret = 0; ret = PowerAPI.PowerReadACValueIndex( IntPtr.Zero, ref _activePolicyGuid, ref _processSetSubGroupGuid, ref _processThrottleMaxGuid, ref cpuThrottleMax); cpuThrottleMax = 50; ret = PowerAPI.PowerWriteACValueIndex( IntPtr.Zero, ref _activePolicyGuid, ref _processSetSubGroupGuid, ref _processThrottleMaxGuid, cpuThrottleMax); ret = PowerAPI.PowerSetActiveScheme(IntPtr.Zero, ref _activePolicyGuid); MessageBox.Show(cpuThrottleMax.ToString()); }
private void SetProcessThrottleMax(uint setValue) { PowerAPI.PowerWriteACValueIndex( IntPtr.Zero, ref _activePolicyGuid, ref _processSetSubGroupGuid, ref _processThrottleMaxGuid, setValue); PowerAPI.PowerSetActiveScheme(IntPtr.Zero, ref _activePolicyGuid); }
private void Form1_Load(object sender, EventArgs e) { this.Icon = Resources.MainIco; taskIcon.Text = this.Text; _counters = new PerformanceCounter[Environment.ProcessorCount]; for (int i = 0; i < _counters.Length; i++) { _counters[i] = new PerformanceCounter("Processor", "% Processor Time", i.ToString()); _lstUsageInfo.Add(new UsageInfo(i, 0)); combCpuNum.Items.Add(i + 1); } _totalCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); combCpuNum.SelectedIndex = _counters.Length - 1; LoadHistoryRecord(); timerRefresh.Enabled = true; #region 电源计划 IntPtr activePolicyGuidPtr = IntPtr.Zero; PowerAPI.PowerGetActiveScheme(IntPtr.Zero, ref activePolicyGuidPtr); _activePolicyGuid = new Guid(PowerAPI.PtrToStructure(activePolicyGuidPtr).ToString()); LoadProcessThrottleSet(); PowerAPI.RegisterPowerSettingNotification(this.Handle, ref _processThrottleMaxGuid, PowerAPI.DEVICE_NOTIFY_WINDOW_HANDLE); #endregion 电源计划 if (_isAutoRun) { new System.Threading.Thread( () => { System.Threading.Thread.Sleep(50); this.WindowState = FormWindowState.Minimized; } ).Start(); } }
private void LoadProcessThrottleSet() { uint cpuThrottle = 0; PowerAPI.PowerReadACValueIndex( IntPtr.Zero, ref _activePolicyGuid, ref _processSetSubGroupGuid, ref _processThrottleMinGuid, ref cpuThrottle); txtProcThrottleMin.Text = cpuThrottle.ToString(); PowerAPI.PowerReadACValueIndex( IntPtr.Zero, ref _activePolicyGuid, ref _processSetSubGroupGuid, ref _processThrottleMaxGuid, ref cpuThrottle); txtProcThrottleMax.Text = cpuThrottle.ToString(); _curProcessThrottleMax = (float)cpuThrottle / 100; }