Optimize Code and Lower CPU usage

Haxaro

Well-known member
Joined
Mar 13, 2009
Messages
105
Programming Experience
1-3
When my form first loads, it runs at about 30k CPU, but after about 10 minutes of use, it goes up to (and stays at) about 70k CPU.

What ways can i optimize my code to allow the CPU usage to stay low, or how can i lower it during the running of the program.

My most concerned areas of the CPU are:

1. I have a web browser, and when a user types in a url and presses go or enter, the CPU jumps about 4k:

VB.NET:
    Private Sub Go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Go.Click
        WebBrowser1.Navigate(OldURL.Text)
        URL.Select()
    End Sub
and
VB.NET:
   Private Sub URL_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles URL.KeyDown
        OldURL = URL.Text
        If e.KeyCode = Keys.Enter Then
            WebBrowser1.Navigate(OldURL)
            URL.Select()
        End If

End Sub

The second worry is when i open other forms, it boosts the CPU up aswell.

the only code for this is:

VB.NET:
Form.Show()


Thanks for any help!

The full code for my program can be found here
 
If the webbrowser control takes to much CPU power, you could "simply" write your own engine - or try to find one which is less heavy (GeckoFX to use the mozilla engine for example).

If .Show takes too much power, I guess that the only solution is to use less and/or different control.

If your app runs at 30% (or 70%) CONSTANTLY (w/o user interaction), you probably have one or more background threads running that consume CPU power. Since I don't know which, it's not possible to say how to improve them.

jm2c
 
Back
Top