Solved

CPU 100% usage VB6 app on Windows 2000 Machine

Posted on 2004-03-25
14
405 Views
Last Modified: 2012-06-22
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
Comment
Question by:sjmmajor
  • 6
  • 6
  • 2
14 Comments
 
LVL 2

Expert Comment

by:robctech
ID: 10679587
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
 

Author Comment

by:sjmmajor
ID: 10679775
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
 
LVL 2

Accepted Solution

by:
robctech earned 500 total points
ID: 10679847
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
 

Author Comment

by:sjmmajor
ID: 10679874
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
 
LVL 2

Expert Comment

by:robctech
ID: 10679947
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
 
LVL 2

Expert Comment

by:robctech
ID: 10679986
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
 

Author Comment

by:sjmmajor
ID: 10680040
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:robctech
ID: 10680070
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
 

Author Comment

by:sjmmajor
ID: 10680127
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
 
LVL 5

Expert Comment

by:g0rath
ID: 10680736
how large is the dataset that you are refreshing?
0
 

Author Comment

by:sjmmajor
ID: 10681031
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
 
LVL 5

Expert Comment

by:g0rath
ID: 10681072
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
 
LVL 2

Expert Comment

by:robctech
ID: 10681106
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
 

Author Comment

by:sjmmajor
ID: 10749580
Do events worked!!  Thanks.  One question though.  What is the rule of when to use Do Events?
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now