Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7025743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:01:05+00:00 2026-05-28T00:01:05+00:00

I want to create a program which can limit cpu usage of a process

  • 0

I want to create a program which can limit cpu usage of a process even when the computer is idle.

I have made a program that set priority of process, but if the computer is idle, the cpu usage can reach 95%. The process contains "element" is the process that I want to limit

private static readonly string[] RestrictedProcess = new[] { "element" }; 
static void ProcessChecker(object o)
{
    List<Process> resProc = new List<Process>();
    foreach(Process p in Process.GetProcesses())
    {
        string s = p.ProcessName;
        foreach(string rp in RestrictedProcess)
        {
            s = s.ToLower();
            if (s.Contains(rp))
                resProc.Add(p);
        }
    }

    foreach(Process p in resProc)
    {
        p.PriorityBoostEnabled = false;
        p.PriorityClass = ProcessPriorityClass.Idle;
        p.MaxWorkingSet = new IntPtr(20000000);
    }

    SetPowerConfig(resProc.Count > 0 ? PowerOption.GreenComputing : PowerOption.Balanced);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:01:06+00:00Added an answer on May 28, 2026 at 12:01 am

    If the program you want to limit is not yours, there are several options:

    • set the process priority as Idle and do not limit the CPU usage as the CPU should be used as much as possible in any case. It’s OK to have your CPU running 100% all the time if there is something useful to do. If the priority is idle, then the CPU usage of this particular process will be reduced if another program requires CPU.
    • if your system is multi-core or multi-cpu, then you might want to set the processor affinity. This will tell your program to use only the processor(s) you want him to use. For example, if your program is multithreaded and able to consume 100% of your two CPUs, then set his affinity to only use one CPU. His usage will then be 50% only.
    • Worst option but actually used by 90% of the “CPU limiter programs” you’ll find on the web: measure the CPU usage of a process and Suspend and Resume it regularly until it’s CPU usage goes to the value you want.

    To suspend/resume a process that is not yours, you’ll have to use P/Invoke (and this requires to have access to the process, so if you are Windows Vista or above, take care of UAC for admin rights):

    /// <summary>
    /// The process-specific access rights.
    /// </summary>
    [Flags]
    public enum ProcessAccess : uint
    {
        /// <summary>
        /// Required to terminate a process using TerminateProcess.
        /// </summary>
        Terminate = 0x1,
    
        /// <summary>
        /// Required to create a thread.
        /// </summary>
        CreateThread = 0x2,
    
        /// <summary>
        /// Undocumented.
        /// </summary>
        SetSessionId = 0x4,
    
        /// <summary>
        /// Required to perform an operation on the address space of a process (see VirtualProtectEx and WriteProcessMemory).
        /// </summary>
        VmOperation = 0x8,
    
        /// <summary>
        /// Required to read memory in a process using ReadProcessMemory.
        /// </summary>
        VmRead = 0x10,
    
        /// <summary>
        /// Required to write to memory in a process using WriteProcessMemory.
        /// </summary>
        VmWrite = 0x20,
    
        /// <summary>
        /// Required to duplicate a handle using DuplicateHandle.
        /// </summary>
        DupHandle = 0x40,
    
        /// <summary>
        /// Required to create a process.
        /// </summary>
        CreateProcess = 0x80,
    
        /// <summary>
        /// Required to set memory limits using SetProcessWorkingSetSize.
        /// </summary>
        SetQuota = 0x100,
    
        /// <summary>
        /// Required to set certain information about a process, such as its priority class (see SetPriorityClass).
        /// </summary>
        SetInformation = 0x200,
    
        /// <summary>
        /// Required to retrieve certain information about a process, such as its token, exit code, and priority class (see OpenProcessToken, GetExitCodeProcess, GetPriorityClass, and IsProcessInJob).
        /// </summary>
        QueryInformation = 0x400,
    
        /// <summary>
        /// Undocumented.
        /// </summary>
        SetPort = 0x800,
    
        /// <summary>
        /// Required to suspend or resume a process.
        /// </summary>
        SuspendResume = 0x800,
    
        /// <summary>
        /// Required to retrieve certain information about a process (see QueryFullProcessImageName). A handle that has the PROCESS_QUERY_INFORMATION access right is automatically granted PROCESS_QUERY_LIMITED_INFORMATION.
        /// </summary>
        QueryLimitedInformation = 0x1000,
    
        /// <summary>
        /// Required to wait for the process to terminate using the wait functions.
        /// </summary>
        Synchronize = 0x100000
    }
    
    [DllImport("ntdll.dll")]
    internal static extern uint NtResumeProcess([In] IntPtr processHandle);
    
    [DllImport("ntdll.dll")]
    internal static extern uint NtSuspendProcess([In] IntPtr processHandle);
    
    [DllImport("kernel32.dll", SetLastError = true)]
    internal static extern IntPtr OpenProcess(
        ProcessAccess desiredAccess,
        bool inheritHandle,
        int processId);
    
    [DllImport("kernel32.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    internal static extern bool CloseHandle([In] IntPtr handle);
    
    public static void SuspendProcess(int processId)
    {
        IntPtr hProc = IntPtr.Zero;
        try
        {
            // Gets the handle to the Process
            hProc = OpenProcess(ProcessAccess.SuspendResume, false, processId);
    
            if (hProc != IntPtr.Zero)
            {
                NtSuspendProcess(hProc);
            }
        }
        finally
        {
            // Don't forget to close handle you created.
            if (hProc != IntPtr.Zero)
            {
                CloseHandle(hProc);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a program, which can encrypt and decrypt a complete file
I want to create a program which opens my file onClick by providing its
I want to create a program that requests from the user 10 grades and
I created one GWT webapplication project.Inthat i want to create servlet program,but in that
I want to create a C# program to provision Windows Mobile devices. I have
I want to create an extremely simple iPhone program that will open a telnet
I want to create a MSWindows Python program that would launch a new Firefox
I want to create a program which calculates how long it will take to
I want to create a software which can accept Print Jobs from other computers,
I want to create a hidden folder using java application. That program should work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.