Difficulty building Progressbar based on performanceCounter % Processor Time in Visual Basic

  • Thread starter Thread starter CodeNemesis
  • Start date Start date
C

CodeNemesis

Guest
Im attempting to create a progressBar which will appear in a "Loading!" form that shows up prior to the success or failure confirmation.

This progressbar, in its current state, loads the form based on a timer.tick. The load process lasts about 4 seconds.

Im trying to create a progressbar that will load based on the remaining processing time for the application instance using PerformanceCounter for % Processor Time.

This is what I have so far, its wrong, and incomplete of course:

Declares public class checking
Public Class checking

Dim i As Integer

Private Function get_cpu_usage(AppName As String)
Dim appCPU As New PerformanceCounter("Processor", "% Processor Time", "*** IE8.0CT Alpha", ".")
Return appCPU.NextValue()
End Function

Event handler for form load, sets parameters for progress bar
Private Sub checking_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
ProgressBar1.Style() = ProgressBarStyle.Marquee
ProgressBar1.Maximum = 100
ProgressBar1.Value = 0
Timer1.Interval = 100
Timer1.Start()
End Sub

Sets timer proprieties and duration of progress bar
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Value -= get_cpu_usage("******* 8.0 Configuration Tool 2013.1.3")
If ProgressBar1.Value = 0 Then
Timer1.Stop()
Me.Visible = False
Me.Close()
End If
End Sub

Closes form and terminates all subroutines
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
main_container.Focus()
End Sub

End Class

I think performance counter for % Processor Time returns a decimal value, something like 20.2, or 14.5. Im not sure if its incremental or decremental.

All I would like to do, is for my progressbar to accurately represent the progress of my application loading. I thought that remaining processing time for the progress tick was a good option to represent that in vb.

Continue reading...
 
Back
Top