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.

In reply to Re: SetPriorityClass(). An explanation of code please. by BrowserUk
in thread SetPriorityClass(). An explanation of code please. by Win

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.