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

CPU 100% usage VB6 app on Windows 2000 Machine

Based off previous question that I got a great answer from, I have around 30 forms and ADO's.  I have changed all my code to opend and close all the connections after they grab their data.  I am still getting machines that are locking up with 100% cpu usage.  I have changed the priorities for the app to high but I am still getting machines locking up.  There is nothing else on these machines although I did see a lot of services that have loaded.  What else can I look for?
0
sjmmajor
Asked:
sjmmajor
  • 6
  • 6
  • 2
1 Solution
 
robctechCommented:
Check any loops that you may have in your code and be sure you have DoEvents during long processing loops or timers which do extensive processing
0
 
sjmmajorAuthor Commented:
Thanks for your quick response.

I do have several timers.  So I need to put a DoEvents in those timer areas?  Within those DoEvents should I put the programing that I had in the timer event?

For example here is some code for one of them.

Private Sub Timer1_Timer()
On Error GoTo errorhandler

Adodc1.Recordset.Filter = adFilterNone
Adodc1.refresh
Adodc1.Recordset.MoveLast
frmfiringorder_5_21.Adodc1.Recordset.Filter = adFilterNone
frmfiringorder_5_21.Adodc1.Recordset.MoveLast
frmfiringorder_5_21.chartsection
Call totalLosses
Adodc1.Recordset.close
frmfiringorder_5_21.Adodc1.Recordset.close
   Exit Sub
errorhandler:
fCancelDisplay = True
ErrorNumber = 0
Err.Clear

Resume Next

End Sub

What do I need to do differently?  
0
 
robctechCommented:
How often does this timer fire?

Additionally I would personally do something like below

Private Sub Timer1_Timer()
On Error GoTo errorhandler

Adodc1.Recordset.Filter = adFilterNone
Adodc1.refresh '//the refresh should be Automatic when you apply the filter
Adodc1.Recordset.MoveLast
frmfiringorder_5_21.Adodc1.Recordset.Filter = adFilterNone
frmfiringorder_5_21.Adodc1.Recordset.MoveLast
frmfiringorder_5_21.chartsection
DoEvents
Call totalLosses '//I'm Putting a doevent before and after as not sure what  
                       '//totallosses  does
DoEvents
'//Your closing the the recordset after timer...where are you actually opening it?
Adodc1.Recordset.close
frmfiringorder_5_21.Adodc1.Recordset.close
   Exit Sub
errorhandler:
fCancelDisplay = True
ErrorNumber = 0
Err.Clear

Resume Next

End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sjmmajorAuthor Commented:
It fires about every 65 seconds.  This happens on 4 forms.  Others are hourly and others are 24 hours based off the system clock.

0
 
robctechCommented:
Well I have never been a fan of ADO controls as they don't handle data communication very well.  the other thing you may wanna look into is using straight ADO connections so
you can open databases and then disconnect and store them....Can honestly tell you even just via your comments that your CPU usage sounds more connect disconnect refresh...sounds like much of it is result of constant opening and closing and scanning of databases...

For Example if you have a database that the data doesn't change very often then you could on load...

Global PrimaryConnection as ADODB.Connection
Global PrimaryRecords as ADODB.Recordset

Private Sub OpenPrimaryRecords()
      PrimaryConnection = '//put your connection string here
      With PrimaryRecords
            .CursorLocation = adUseClient
            .LockType = adLockBatchOptimistic
            .ActiveConnection = dbfConn
            .Source = '//Enter Your SQL String Here
            .Open
            .ActiveConnection = Nothing
End Sub

Now the database is replicated on the client machine...filters and moves execute much quicker as it doesn't have to actually go through the data connection to do what it wants..hopefull this makes sense to you and helps some of your problems
0
 
robctechCommented:
I'll help you out on this as much as I can but sounds like its a pretty big project to make modifications to....and don't take this the wrong way but you may possibly want to look at making other major changes to the program if you can as it sounds as if there is alot of redundancy...(code written over and over...)

Anyways keep them coming and as I said help as much as I can
0
 
sjmmajorAuthor Commented:
I would still need the data refreshed.  I need to go out and get information that changes every 5 mins, every hour, every 24 hours.  How would I go about doing this?  Isn't it hitting the database just as much?
0
 
robctechCommented:
5 minute timer
Private Sub DataRefreshTimer_Timer()
    PrimaryRecords.ActiveConnection = PrimaryConnection
    PrimaryRecords.Requery
End sub

1jr minute timer
Private Sub DataRefreshTimer_Timer()
    PrimaryRecords.ActiveConnection = PrimaryConnection
    PrimaryRecords.Requery
End sub

Etc....
0
 
sjmmajorAuthor Commented:
I will take a look.  Let you know in a while.  Thanks for your help.  If you think of anything else please let me know.

0
 
g0rathCommented:
how large is the dataset that you are refreshing?
0
 
sjmmajorAuthor Commented:
I just change things to include the DoEvents and I am running a test through the night.  The database sets, I don't think are very big.  They can be up to about 144 rows and at the most 50 columns.  I purge every Saturday.  I have rolled out this program and then started getting the CPU 100% error.  I guess I finally added too much to the program.  But I do like the Global Connection.  I am just not sure how to do it.  What does Source capture?  Can you explain line for line what the above does?

I do appreciate everyones help.  
0
 
g0rathCommented:
sometimes with too large of a dataset you need to implement your own paging. As in you only load the # of records you are really displaying.

So if you have 50K records but only show 10 at a time, then you just load 10, and remember where you are at...this is the way access does it....loading 10 at a time and only loading the next 10 when you move the scrollbar....

Here are various methods to help increase that area of performance....

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20175389.html?query=ado+paging+grid&searchType=all
0
 
robctechCommented:
Explanation of Options

      .CursorLocation = adUseClient

Uses client-side cursors supplied by a local cursor library. Local cursor services often will allow many features that driver-supplied cursors may not, so using this setting may provide an advantage with respect to features that will be enabled. For backward compatibility, the synonym adUseClientBatch is also supported.

            .LockType = adLockBatchOptimistic

Optimistic locking, record by record—the provider uses optimistic locking, locking records only when you call the Update method.

            .ActiveConnection = This is your Dataconnection object

            .Source = '//Enter Your SQL String Here

Use the Source property to specify a data source for a Recordset object using one of the following: a Command object variable, an SQL statement, a stored procedure, or a table name. The Source property is read/write for closed Recordset objects and read-only for open Recordset objects.

Hope this helps
0
 
sjmmajorAuthor Commented:
Do events worked!!  Thanks.  One question though.  What is the rule of when to use Do Events?
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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