I have a VFP7 app that does some pretty major number crunching while
generating particular reports.

My client has asked that I limit CPU usage to a particular value (say 70%)
at specific places within the app.

How can I do that within VFP?

Thanks,

Brian

Re: Limit CPU Usage by Fred

Fred
Tue Oct 24 01:51:39 CDT 2006

You'd have to use some Windows API calls, if it is even possible. Are you
running something on a server, is that why you're being asked to limit it?
Normally, you'd run your app on a workstation, so there should be no reason
to limit it.

--
Fred
Microsoft Visual FoxPro MVP


"Brian McKillop" <brian.nospamforme@mckillopassociates.com.au> wrote in
message news:kgh%g.52074$rP1.49827@news-server.bigpond.net.au...
>I have a VFP7 app that does some pretty major number crunching while
>generating particular reports.
>
> My client has asked that I limit CPU usage to a particular value (say 70%)
> at specific places within the app.
>
> How can I do that within VFP?
>
> Thanks,
>
> Brian
>



Re: Limit CPU Usage by Josh

Josh
Tue Oct 24 07:16:59 CDT 2006

On Mon, 23 Oct 2006 23:51:39 -0700, "Fred Taylor" <ftaylor@mvps.org!REMOVE>
wrote:

>You'd have to use some Windows API calls, if it is even possible. Are you
>running something on a server, is that why you're being asked to limit it?
>Normally, you'd run your app on a workstation, so there should be no reason
>to limit it.

Hmm. I run an app that does an xmltocursor() call - that basically freezes the
workstation for 20 minutes, with cpu processing at 100% (the app has 98 % of the
cpu usage, with kernel times up there as well).

I can see wanting an application to be self-limiting.

--- AntiSpam/harvest ---
Remove X's to send email to me.

Re: Limit CPU Usage by Giancarlo

Giancarlo
Tue Oct 24 07:48:00 CDT 2006

SetPriorityClass can be your friend in cases like this.

Regards,

Giancarlo

"Brian McKillop" <brian.nospamforme@mckillopassociates.com.au> wrote in
message news:kgh%g.52074$rP1.49827@news-server.bigpond.net.au...
>I have a VFP7 app that does some pretty major number crunching while
>generating particular reports.
>
> My client has asked that I limit CPU usage to a particular value (say 70%)
> at specific places within the app.
>
> How can I do that within VFP?
>
> Thanks,
>
> Brian
>


Re: Limit CPU Usage by Claude

Claude
Tue Oct 24 08:47:02 CDT 2006

In an appropriate place (like in a processor intensive loop), put the api
call to sleep as in:
DECLARE Sleep IN WIN32API INTEGER
FOR lncount = 1 TO READSIZE
lcInput=m.lcInput+ CHR(laBlob1(lncount))
Sleep(0) && 0 allows the processor to do other things
ENDFOR
If you suspect memory might also be a factor, try:
SYS(3050, 1, VAL(SYS (3050, 1, 0)) / 3) && uses 1/3 available mem

Claude Fox
ActiveVFP - Open Source Web Development with VFP
http://www.activevfp.com
"Brian McKillop" <brian.nospamforme@mckillopassociates.com.au> wrote in
message news:kgh%g.52074$rP1.49827@news-server.bigpond.net.au...
>I have a VFP7 app that does some pretty major number crunching while
>generating particular reports.
>
> My client has asked that I limit CPU usage to a particular value (say 70%)
> at specific places within the app.
>
> How can I do that within VFP?
>
> Thanks,
>
> Brian
>



Re: Limit CPU Usage by Roger

Roger
Tue Oct 24 08:56:54 CDT 2006

"Josh Assing" <XjoshX@jassing.com> wrote in message
news:vu0sj2p0q41vnhdbc0ndhsgc2qploi6qm9@4ax.com
> On Mon, 23 Oct 2006 23:51:39 -0700, "Fred Taylor"
> <ftaylor@mvps.org!REMOVE> wrote:
>
>> You'd have to use some Windows API calls, if it is even possible.
>> Are you running something on a server, is that why you're being
>> asked to limit it? Normally, you'd run your app on a workstation, so
>> there should be no reason to limit it.
>
> Hmm. I run an app that does an xmltocursor() call - that basically
> freezes the workstation for 20 minutes, with cpu processing at 100%
> (the app has 98 % of the cpu usage, with kernel times up there as
> well).
>
> I can see wanting an application to be self-limiting.

OK, not absolutely precise about limiting CPU usage but
you can change your app's priority. Something like ...

#Define Priority_Normal 32
#Define Priority_BelowNormal 16384
lcComputer = "."
oWMI = GetObject("winmgmts:" + ;
"{impersonationlevel=impersonate}!\\" + ;
lcComputer + ;
"\root\cimv2")

loProcesses = oWMI.ExecQuery("Select * " +;
"From Win32_Process")

For Each loProcess In loProcesses
If Upper( loProcess.Name) = "VFP9.EXE"
loProcess.SetPriority(Priority_BelowNormal)
Exit
Endif
Next

* Do your CPU-intensive code here

* Then reset your app's priority back to normal
loProcess.SetPriority(Priority_Normal)

HTH

Roger


>
> --- AntiSpam/harvest ---
> Remove X's to send email to me.



Re: Limit CPU Usage by Claude

Claude
Tue Oct 24 09:11:10 CDT 2006

Here are the APIs to achieve a more precise processor usage(Use with care!):

DECLARE INTEGER GetCurrentThread ;

IN WIN32API


DECLARE INTEGER GetThreadPriority ;

IN WIN32API ;

INTEGER tnThreadHandle

DECLARE INTEGER SetThreadPriority ;

IN WIN32API ;

INTEGER tnThreadHandle,;

INTEGER tnPriority

FUNCTION GetCurrentThread

************************************************************************

* GetCurrentThread

*********************************

*** Function: Returns handle to the current Process/Thread

*** Return: Process Handle or 0

************************************************************************

RETURN GetCurrentThread()

ENDFUNC

* GetProcess

************************************************************************

* GetThreadPriority

*********************************

*** Function: Gets the current Priority setting of the thread.

*** Use to save and reset priority when bumping it up.

*** Pass: tnThreadHandle

************************************************************************

FUNCTION GetThreadPriority

LPARAMETER tnThreadHandle

RETURN GetThreadPriority(tnThreadHandle)

ENDFUNC

* GetThreadPriority

FUNCTION SetThreadPriority

************************************************************************

* SetThreadPriority

*********************************

*** Function: Sets a thread process priority. Can dramatically

*** increase performance of a task.

*** Pass: tnThreadHandle

*** tnPriority 0 - Normal

*** 1 - Above Normal

*** 2 - Highest Priority

*** 15 - Time Critical

*** 31 - Real Time

************************************************************************

LPARAMETER tnThreadHandle,tnPriority

RETURN SetThreadPriority(tnThreadHandle,tnPriority)

ENDFUNC

* GetThreadPriority

"Claude Fox" <cfuchs@activevfp.com> wrote in message
news:uynQmL39GHA.1200@TK2MSFTNGP02.phx.gbl...
> In an appropriate place (like in a processor intensive loop), put the api
> call to sleep as in:
> DECLARE Sleep IN WIN32API INTEGER
> FOR lncount = 1 TO READSIZE
> lcInput=m.lcInput+ CHR(laBlob1(lncount))
> Sleep(0) && 0 allows the processor to do other things
> ENDFOR
> If you suspect memory might also be a factor, try:
> SYS(3050, 1, VAL(SYS (3050, 1, 0)) / 3) && uses 1/3 available mem
>
> Claude Fox
> ActiveVFP - Open Source Web Development with VFP
> http://www.activevfp.com
> "Brian McKillop" <brian.nospamforme@mckillopassociates.com.au> wrote in
> message news:kgh%g.52074$rP1.49827@news-server.bigpond.net.au...
>>I have a VFP7 app that does some pretty major number crunching while
>>generating particular reports.
>>
>> My client has asked that I limit CPU usage to a particular value (say
>> 70%) at specific places within the app.
>>
>> How can I do that within VFP?
>>
>> Thanks,
>>
>> Brian
>>
>
>