Win, you quote me saying the correct way to do this is by using SetPriorityClass() on your process and setting it to IDLE_PRIORITY_CLASS. in Re: CPU usage Windows OP.
You have then picked up the code from Re^5: how to change process & thread priority on Win32 ? and started playing with it, but that code has nothing to do with setting process priorities or the SetPriorityClass() call I suggested to you. It deals only with setting thread priorities which are a different and completely unrelated thing to your actual goal.
I could annotate the above code to clarify what it is doing, and would if I thought it would help you, but it won't! I am assuming that I know what your goal is, which is difficult for me to assertain as I've completely lost sight of what it is you are trying to achieve--and I think you may have also!
One problem is that you keep starting new threads and making belated posts in old threads that all seem to be vaguely related to the same problem:
Frankly, I've gotten weary trying to follow your leaps and bounds around, and work out exactly what it is you are trying to achieve. Have you ever posted here under a different id? Because your scattergun approach to problem solving reminds me vaguely of another monk that has a habit of picking up random pieces of source code and then complaining that they don't do what he wants them to do.
Okay. Assuming what you were trying to do when you grabbed the above pieve of code, is to change the process priority class of a perl script, then the simplest way of doing that is to change it when you start the script:
start /LOW perl yourscript.pl
That's it, job done. No messing with win32 apis or threads or anything else. If you want it so that you don't have to type those extra 8 characters every time, put it in a batch file.
copy con yourscript.cmd
start /LOW perl yourscript.pl
^Z
Now when you type \path\to\yourscript, the batch file will start your perl script running at idle priority. You might want to add /B to that so that it runs in the background. Use help start for the other options.
If that does not solve your actual problem, then can I suggest that you reply here (*not* another new thread!), and describe exactly what problem it is that you are trying to solve, rather than how you are currently trying to solve it. You will then give us a chance to propose a solution to that problem, rather than running around fighting fires as you leap off in all directions.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|