Jump to content

Windows 10 and ProcessSetPriority


Recommended Posts

Back after ten years away, so please consider me a newbie.

I researched this High Priority issue and came up with nothing to explain what I am seeing re ProcessSetPriority failing to set to "real time"

I am running newest Windows 10, and MS Office 2019.  I need to  execute some code REALLY fast so I looked into ProcessSetPriority (besides trying for best practice for speed in the code itself).  However , if I try to set priority to "real time" with ProcessSetPriority, it defaults back to "high", one level lower.

Help file for ProcessSetPriority has no discussion about the pop-up window you see in Windows 10 if you manually try to set priority to real time. Manually you get a warning and have to agree to setting it real time. It does set to real time when you accept the warning.

You can see my problem if you run the Help File example code for ProcessGetPriority, but change the third option to "real time" instead of "very high".  See my modified version attached which checks to see if the actual priorities match the target.

#include <MsgBoxConstants.au3>
#include <Process.au3>

Local $i_Priority_Level, $i_Notepad_PID, $i_ArrayItem
Local $a_RunLevels[3] = [0, 4, 5] ;low, high, real time
; Get Priority Level of this instance of AutoIt Scripting Engine
$i_Priority_Level = _ProcessGetPriority(@AutoItPID)
MsgBox($MB_SYSTEMMODAL, "AutoIt Script", "Should be 2,      IS: " & $i_Priority_Level)
$i_Notepad_PID = Run(@ComSpec & ' /k notepad.exe', '', @SW_HIDE)
For $i_ArrayItem = 0 To 2
    ProcessSetPriority($i_Notepad_PID, $a_RunLevels[$i_ArrayItem])
    $i_Priority_Level = _ProcessGetPriority($i_Notepad_PID)
    If $i_Priority_Level = $a_RunLevels[$i_ArrayItem] Then
        MsgBox($MB_SYSTEMMODAL, "Notepad Priority", "Should be   " & $a_RunLevels[$i_ArrayItem] & @CRLF & "    Matches,    is :  " & $i_Priority_Level)
    Else
        MsgBox($MB_SYSTEMMODAL, "Notepad Priority", "Should be   " & $a_RunLevels[$i_ArrayItem] & @CRLF & " *DOES NOT MATCH*  is: " & $i_Priority_Level)
    EndIf
Next
ProcessClose('notepad.exe')

Am I doing something wrong?  How can I set Priority to High other than brute force manually?

 

 

 

Link to comment
Share on other sites

Add #RequireAdmin to the beginning of your script and see if it works as expected.  It does for me.

Link to comment
Share on other sites

46 minutes ago, photonblaster said:

ProcessSetPriority failing to set to "real time"

That TheXman say would be my answer too, now,  ..you're sure you wanna set it to RealTime !??. Maybe you can brake the code in separate functions and do some IPC between them, but, to need "real time" ... there should be a better way to that you need. ( my unrequested 2 cents. )

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Thanks!!!!!!!!

TheXman:  Works for me too.

 

On 2/7/2021 at 8:54 PM, argumentum said:

Maybe you can brake the code in separate functions and do some IPC between them, but, to need "real time" ... there should be a better way to that you need.

argumentum, thanks for your comments. I am running speed tests to see if I need to go to real time, maybe "high" is good enough.  Right now  I get ~30% reduction in execution time using real time.  I am trying different, dare I say more elegant, ways to speed it up of course since the priority is a hammer, but I need the absolute fastest analysis so I will always be using at least high priority.  I have 8 core, 5GHZ CPU, and only two cores go to 85% utilization right now so real time does not seem to be a problem (yet, or that I see).  I am working with Excel 2019 which is supposed to be optimized for multi-threading, but my data analysis is very linear, not much parallel processing algorithms available.

I am guessing IPC is inter process communications?  Can you steer me in the right direction to look into this?  Isn't things like Autoit Excel functions to read, manipulate data inside AutoIT, write back answers basically IPC?  MS says using the clipboard is one way to implement IPC, but this I think is usually very slow. Interprocess Communications - Win32 apps | Microsoft Docs

I expect I will be posting later to get some pointers re speeding things up after I have pushed myself to the limit of my own devices.

 

Link to comment
Share on other sites

17 hours ago, photonblaster said:

Can you steer me in the right direction to look into this?

I've got a "note to self" at https://www.autoitscript.com/forum/profile/4574-argumentum/?tab=field_core_pfield_11

There you'll find a bunch of handy stuff, like an IPC set of examples:

where you can run one script in one core and other scripts in other cores but you'll have to chop the scripts in chunks that do specific stuff and IPC the result and state to the, call it "main" script.
One such an example of IPC usage is 

where it runs a bunch of processes concurrently and gathers the data in the main/gui script.

With experience creativity expands. Look around the forum. There are good examples around :) 

 

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...