Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Increasing priority level 1

Status
Not open for further replies.

KornGeek

Programmer
Joined
Aug 1, 2002
Messages
1,961
Location
US
I have an app written in VB6 that does device communications across a serial port. We discovered that while this is running in the background, if the user clicks on the scroll bar of an Internet Explorer window and holds the button down, some data is lost. I've seen it range from 2 bytes to about 12 bytes lost, plus other bytes corrupted.

When running older DOS programs, Windows allows you to set several parameters such as Idle Sensitivity and others to set the system priority of the app. Is there some way to increase the resources reserved for my app? Am I barking up the wrong tree?

I appreciate any guidance you can offer.
 
ive been experiencing similar problems with my serial port program
 
The Good News:
I have found a way to do this using the Windows API function SetPriorityClass. It successfully upgrades my program to High Priority when I begin my serial communications, and downgrades it back to Normal Priority when it is done.

The Bad News:
This doesn't completely eliminate the problem, although it greatly reduces the occurrences of it. Also, this hogs processor time, maxing out my processor usage. Other programs don't run very well. This is almost as bad as the original problem. I think I started down the wrong path here.
 
Korn,

look at the thread i started "serial port communication problem". i originally used a loop that checked if the input buffer was empty. i had doevents inside the loop. this works but occasionally it screws up(i think it spends too long doing events). so i changed my approach. as you can see im having problems with this approach as well.
 
your solution might work for me though. my program runs on a laptop dedicated to this task. could you give me help with using the Windows API function SetPriorityClass?
 
I can't offer too much help. I suggest reading the documentation Microsoft has on this. Be careful using AboveNormal or BelowNormal priority classes, which are OS dependant. Also, aviod RealTime. It's too powerful. Here is some sample code:

Private Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long

Public Const REALTIME_PRIORITY_CLASS = &H100
Public Const HIGH_PRIORITY_CLASS = &H80
Public Const ABOVE_NORMAL_PRIORITY_CLASS = &H8000
Public Const NORMAL_PRIORITY_CLASS = &H20
Public Const BELOW_NORMAL_PRIORITY_CLASS = &H4000
Public Const IDLE_PRIORITY_CLASS = &H40

Public Sub SetPriority(lngPriorityClass As Long)
Dim hProc As Long

On Error GoTo SetPriorityErr

hProc = GetCurrentProcess
SetPriorityClass hProc, lngPriorityClass

SetPriorityExit:
Exit Sub

SetPriorityErr:
HandleError Err.Number, Err.Description, AppTitle
Err.Clear

End Sub
 
thanks for the help, and good luck. maybe the second approach i tried might be helpful for you. looks like it WILL let me give you a star :+)
 
im not so sure about avoiding real time. i am gathering data in real time and my app is maximized when it runs as the "only" app. ill try high first though i guess.
 
i think next time im at the site i will check and make sure they dont have any "housekeeping" tasks scheduled too.
 
Private Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long


why is SetPriorityClass declared as Private? i now have 4 API declarations in my project's module now and the other 3 are all Public.
 
The Private vs Public is just how I was using it in my module. I wanted other modules to be able to use GetCurrentProcess if they needed it, but I wanted to keep SetPriorityClass limited to my module. You can set it how you need.

In the Microsoft documentation, they recommend against using the RealTime setting. That could potentially interfere with critical parts of the OS and introduce more errors than it prevents. Read the documentation before doing this.
 
thanks again. i was thinking of setting priority level when my second form loads. i havent worked with API calls at all really so not sure if it matters when or where i do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top