mjs082969
asked on
I need to put my VB hog on a diet! Resource hog!
I have an app I wrote which is actually pretty intensive. It does alot fo data base access, calculation using about 17 different datasources. During execution of the application, the system become totally bogged down with this process!
I have used the sleep API in my attempts to solve similar situations. Unfortunately, I had no luck with that. Does anyone have any ideas how to lean up this pig so i can run other processes while it is going?
Thanks In Advance,
Michael
I have used the sleep API in my attempts to solve similar situations. Unfortunately, I had no luck with that. Does anyone have any ideas how to lean up this pig so i can run other processes while it is going?
Thanks In Advance,
Michael
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.calbay.com/doevents.htm#ED
Try this
set priority to THREAD_PRIORITY_LOWEST
ie.
Const THREAD_BASE_PRIORITY_IDLE = -15
Const THREAD_BASE_PRIORITY_LOWRT = 15
Const THREAD_BASE_PRIORITY_MIN = -2
Const THREAD_BASE_PRIORITY_MAX = 2
Const THREAD_PRIORITY_LOWEST = THREAD_BASE_PRIORITY_MIN
Const THREAD_PRIORITY_HIGHEST = THREAD_BASE_PRIORITY_MAX
Const THREAD_PRIORITY_BELOW_NORM AL = (THREAD_PRIORITY_LOWEST + 1)
Const THREAD_PRIORITY_ABOVE_NORM AL = (THREAD_PRIORITY_HIGHEST - 1)
Const THREAD_PRIORITY_IDLE = THREAD_BASE_PRIORITY_IDLE
Const THREAD_PRIORITY_NORMAL = 0
Const THREAD_PRIORITY_TIME_CRITI CAL = THREAD_BASE_PRIORITY_LOWRT
Const HIGH_PRIORITY_CLASS = &H80
Const IDLE_PRIORITY_CLASS = &H40
Const NORMAL_PRIORITY_CLASS = &H20
Const REALTIME_PRIORITY_CLASS = &H100
Private Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As Long, ByVal nPriority As Long) As Long
Private Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
Private Declare Function GetThreadPriority Lib "kernel32" (ByVal hThread As Long) As Long
Private Declare Function GetPriorityClass Lib "kernel32" (ByVal hProcess As Long) As Long
Private Declare Function GetCurrentThread Lib "kernel32" () As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim hThread As Long, hProcess As Long
'retrieve the current thread and process
hThread = GetCurrentThread
hProcess = GetCurrentProcess
'set the new thread priority to "lowest"
SetThreadPriority hThread, THREAD_PRIORITY_LOWEST
'set the new priority class to "idle"
SetPriorityClass hProcess, IDLE_PRIORITY_CLASS
'print some results
Me.AutoRedraw = True
Me.Print "Current Thread Priority:" + Str$(GetThreadPriority(hTh read))
Me.Print "Current Priority Class:" + Str$(GetPriorityClass(hPro cess))
End Sub
set priority to THREAD_PRIORITY_LOWEST
ie.
Const THREAD_BASE_PRIORITY_IDLE = -15
Const THREAD_BASE_PRIORITY_LOWRT
Const THREAD_BASE_PRIORITY_MIN = -2
Const THREAD_BASE_PRIORITY_MAX = 2
Const THREAD_PRIORITY_LOWEST = THREAD_BASE_PRIORITY_MIN
Const THREAD_PRIORITY_HIGHEST = THREAD_BASE_PRIORITY_MAX
Const THREAD_PRIORITY_BELOW_NORM
Const THREAD_PRIORITY_ABOVE_NORM
Const THREAD_PRIORITY_IDLE = THREAD_BASE_PRIORITY_IDLE
Const THREAD_PRIORITY_NORMAL = 0
Const THREAD_PRIORITY_TIME_CRITI
Const HIGH_PRIORITY_CLASS = &H80
Const IDLE_PRIORITY_CLASS = &H40
Const NORMAL_PRIORITY_CLASS = &H20
Const REALTIME_PRIORITY_CLASS = &H100
Private Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As Long, ByVal nPriority As Long) As Long
Private Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
Private Declare Function GetThreadPriority Lib "kernel32" (ByVal hThread As Long) As Long
Private Declare Function GetPriorityClass Lib "kernel32" (ByVal hProcess As Long) As Long
Private Declare Function GetCurrentThread Lib "kernel32" () As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim hThread As Long, hProcess As Long
'retrieve the current thread and process
hThread = GetCurrentThread
hProcess = GetCurrentProcess
'set the new thread priority to "lowest"
SetThreadPriority hThread, THREAD_PRIORITY_LOWEST
'set the new priority class to "idle"
SetPriorityClass hProcess, IDLE_PRIORITY_CLASS
'print some results
Me.AutoRedraw = True
Me.Print "Current Thread Priority:" + Str$(GetThreadPriority(hTh
Me.Print "Current Priority Class:" + Str$(GetPriorityClass(hPro
End Sub
When you say the system got bogged down, do you mean your VB application?? If so, vinnid79's suggestion of using do events will free up your processor and allow you to run other tasks. Or when you say "system" are you reffering to a mainframe you are connecting to from VB? I know that many db2 applications if not coded carefully in VB can really bog down a Mainframe using DB2 because all the SQL statements need to be bound and prepared everytime. Depending on what databases you are going and your answer to my question above, there are a number of things you can do to LEAN your application.
Cheers,
JDC0724
Cheers,
JDC0724
I would look into closing each connection to the datasource after you are done with it.
example
set rs = new recordset
rs.open Strsql,dbconnection,option s,options
do until rs.eof
code...
loop
if rs.state = adstateopen then
rs.close
set rs = nothing
endif
making that many
example
set rs = new recordset
rs.open Strsql,dbconnection,option
do until rs.eof
code...
loop
if rs.state = adstateopen then
rs.close
set rs = nothing
endif
making that many
Making that many connections and not closing them will create overhead. Is it slow from the beginning?
Or as it runs?
Or as it runs?
ASKER
Thank you people!