Change Process priority does not work

前端 未结 3 1864
谎友^
谎友^ 2021-02-07 08:37

I run an Audio Repeater application which allows me to play sound through my headset & Speakers at the same time. The Application itself has an ability to set itself to \"Re

相关标签:
3条回答
  • 2021-02-07 09:18

    Try this :

    using (Process p = Process.GetCurrentProcess())
        p.PriorityClass = ProcessPriorityClass.High;  
    
    0 讨论(0)
  • 2021-02-07 09:24

    You need to run YOUR script with administrative privilege.

    0 讨论(0)
  • 2021-02-07 09:26

    You can run as an administrator or remove UAC because you need rights to access to a Process you did not run.

    This works for me :

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    // #define DEBUG
    
    namespace ProcessRealtime
    {
        class PUBG_RealTime
        {
            static string processName = "TslGame";
            static ProcessPriorityClass newPriority = ProcessPriorityClass.High;
    
            static void Main(string[] args)
            {
    #if DEBUG
                PutDebug("Start!");
    #endif
                Process[] processes = Process.GetProcessesByName(processName);
    #if DEBUG
                PutDebug(processes.Length + " processed found");
    #endif
                foreach (Process proc in processes)
                {
    #if DEBUG
                    PutDebug("New process found");
    #endif
                    Console.WriteLine("Changing Priority for id:" + proc.Id + " to " + newPriority.ToString());
                    proc.PriorityClass = newPriority;
    #if DEBUG
                    PutDebug("Changed priority for " + proc.Id);
    #endif
                }
    #if DEBUG
                PutDebug("No more processes..");
    #endif
                Console.Write("Press a key, it's over !");
                Console.ReadLine();
            }
    
    #if DEBUG
            static bool debug = true;
            static int debugInc = 1;
            static void PutDebug(string info = "")
            {
                if(debug){
                    Console.WriteLine("Debug" + debugInc + ": " + info);
                    debugInc++;
                }
            }
    #endif
        }
    }
    
    0 讨论(0)
提交回复
热议问题