• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 133
  • Last Modified:

Controlling FG & BG timeslicing

I need to control the way Windows allocates processor time to the foreground and background tasks from within VB6. The foreground tasks are getting too much processor time causing the background tasks to barely do their thing. Is there a way to do this in VB6 using API calls or whatever?
0
kenvc
Asked:
kenvc
  • 3
  • 2
1 Solution
 
mark2150Commented:
Sprinkle DoEvents inside your loops and in your code to cede some time to other tasks. Do Async data queries.

M
0
 
mcriderCommented:
Be careful when using doevents...

Any time you temporarily yield the processor within an event procedure, make sure the procedure  is not executed again from a different part of your code before the first call returns; this could cause unpredictable results. In addition, do not use DoEvents if other applications could possibly interact with your procedure in unforeseen ways during the time you have yielded control.

The doevents should be used in both the foreground and background applications...

Cheers!
0
 
kenvcAuthor Commented:
This method will not work because it assumes I have access to the source code of all the programs that could be running on my computer.

I need a solution (probably an API call) that can be called 1 time from VB6 that permanently changes the way Windows allocates cpu usage on all FG and BG tasks globally for ALL programs. ie. change from 90%/10% to 50%/50% or whatever.

It can be a permanent change or it can be a change that just lasts until the system is restarted... that part does not matter.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
mark2150Commented:
That call doesn't exist.

If you put the DoEvents in your own code you should see an immediate performance boost. Try it and see. The other code will not hog the resources because they are the BG tasks. You get preference because you're the FG task.

M
0
 
mcriderCommented:
I think what you're looking for is the SetPriorityClass and the SetThreadPriority APIs.

SetPriorityClass is defined here:
http://msdn.microsoft.com/library/psdk/winbase/prothred_9z1v.htm

SetThreadPriority is defined here:
http://msdn.microsoft.com/library/psdk/winbase/prothred_9f5l.htm

If you have access to assembly (MASM) you can use Set_Time_Slice_Priority defined here:
http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/ddkdoc/win95ddk/kernel_98vq.htm


Cheers!
0
 
mcriderCommented:
This is really bizzare on microsofts part... if you click on the references I gave you above, you get the message "this page has moved"...

However, if you highlight the URL and copy it to the clipboard and paste it to the browser address line, or type the URL in manually, you get the page...

Really weird!


Cheers!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now