Progress bar bars are not showing


G

Guest

Hello,
I have a problem with my progress bar, as shown in the attached
code, the values on the bar are incremented within a threaded timer event.
The timer works fine and ticks all the way through. However when you Add a
new status bar to the form with a Progress bar and then immediately perform
some intense programming that uses a lot of processor resources, the bars in
the progress bar are not displayed, even though the timer appears to be going
in the background. Within the timer event the line that increments the bar
value of the progress bar seems to be ignored completely
bar.value += 1 ' no debug messages are printed after this and it is not
caught in a try catch thing,

When you add the progress bar on it's own with no processing going on
afterwards
it works fine

Any help would be greatly appreciated.
Robert

Here is my code

*** threaded timer event ** - time gap = 300ms
Private Sub TimerClick(ByVal stateinfo As Object)
Dim panel As StatusPanel

' Scan each of the status panels
For Each panel In Me.SbcBackupRestore.StatusPanels
' Is it designated for time information?


Dim bar As ProgressBar
' Is it designated for progrss information?
If (CType(panel.Tag, Integer) = 2) Then

bar = CType(panel.Controls(0), ProgressBar)


Debug.WriteLine("***** B4 adding 1 to the bar value =
*******")
Debug.WriteLine(bar.Value)

If bar.Value < bar.Maximum Then
Try
bar.Value += 1 'This line seems to be ignored
completely
Catch ex As Exception
ex.ToString()
MsgBox("Error incrementing the bar value")
End Try
Debug.WriteLine("b4 updating the bar value")
bar.Update()
End If

Debug.WriteLine("after incrementing - new value = " &
bar.Value)
Debug.WriteLine("*****Added a bar*******")
If (bar.Value >= bar.Maximum) Then
bar.Value = bar.Minimum
End If
End If
Next


End Sub


Private Sub AddStatusBar(ByVal tagvalue As Integer)

Dim panel As New StatusPanel
panel.Text = StrStatusBarText
panel.RequestedWidth = 160

panel.AutoSizing = StatusBarPanelAutoSize.Contents
panel.Image = ImageList1.Images(IntStatusBarImageIndex)
panel.Alignment = StringAlignment.Near


' Progress control overrides some values
If (tagvalue = 2) Then
panel.AutoSizing = StatusBarPanelAutoSize.None

Dim bar As New ProgressBar
bar.Minimum = 0
bar.Maximum = 30
bar.Dock = DockStyle.Fill
panel.Controls.Add(bar)
End If


panel.Tag = tagvalue
Me.SbcBackupRestore.StatusPanels.Add(panel)

End Sub

'**********Calling code *********

Me.SbcBackupRestore.StatusPanels.Clear()
StrStatusBarText = "Restoring database..."
AddStatusBar(0)
AddStatusBar(2)
Me.SbcBackupRestore.Update()
strExec = "RESTORE DATABASE " & DatabaseName & " FROM
DISK = '" & FileName & "' WITH REPLACE, MOVE '" & strDatFile & "' TO '" &
strDataPath & DatabaseName & ".mdf', MOVE '" & strLogfile & "' TO '" &
strDataPath & DatabaseName & ".ldf'"
strquery = strExec
Call MyDataAccess.ExecuteUpdateStatement(strquery, GblConnectionString2)
 
Ad

Advertisements

K

Ken Tucker [MVP]

Hi,

Instead of bar.update. try application.doevents. Gives status bar
a chance to redraw itself.

Ken
----------------------
Hello,
I have a problem with my progress bar, as shown in the attached
code, the values on the bar are incremented within a threaded timer event.
The timer works fine and ticks all the way through. However when you Add a
new status bar to the form with a Progress bar and then immediately perform
some intense programming that uses a lot of processor resources, the bars in
the progress bar are not displayed, even though the timer appears to be
going
in the background. Within the timer event the line that increments the bar
value of the progress bar seems to be ignored completely
bar.value += 1 ' no debug messages are printed after this and it is not
caught in a try catch thing,

When you add the progress bar on it's own with no processing going on
afterwards
it works fine

Any help would be greatly appreciated.
Robert

Here is my code

*** threaded timer event ** - time gap = 300ms
Private Sub TimerClick(ByVal stateinfo As Object)
Dim panel As StatusPanel

' Scan each of the status panels
For Each panel In Me.SbcBackupRestore.StatusPanels
' Is it designated for time information?


Dim bar As ProgressBar
' Is it designated for progrss information?
If (CType(panel.Tag, Integer) = 2) Then

bar = CType(panel.Controls(0), ProgressBar)


Debug.WriteLine("***** B4 adding 1 to the bar value =
*******")
Debug.WriteLine(bar.Value)

If bar.Value < bar.Maximum Then
Try
bar.Value += 1 'This line seems to be ignored
completely
Catch ex As Exception
ex.ToString()
MsgBox("Error incrementing the bar value")
End Try
Debug.WriteLine("b4 updating the bar value")
bar.Update()
End If

Debug.WriteLine("after incrementing - new value = " &
bar.Value)
Debug.WriteLine("*****Added a bar*******")
If (bar.Value >= bar.Maximum) Then
bar.Value = bar.Minimum
End If
End If
Next


End Sub


Private Sub AddStatusBar(ByVal tagvalue As Integer)

Dim panel As New StatusPanel
panel.Text = StrStatusBarText
panel.RequestedWidth = 160

panel.AutoSizing = StatusBarPanelAutoSize.Contents
panel.Image = ImageList1.Images(IntStatusBarImageIndex)
panel.Alignment = StringAlignment.Near


' Progress control overrides some values
If (tagvalue = 2) Then
panel.AutoSizing = StatusBarPanelAutoSize.None

Dim bar As New ProgressBar
bar.Minimum = 0
bar.Maximum = 30
bar.Dock = DockStyle.Fill
panel.Controls.Add(bar)
End If


panel.Tag = tagvalue
Me.SbcBackupRestore.StatusPanels.Add(panel)

End Sub

'**********Calling code *********

Me.SbcBackupRestore.StatusPanels.Clear()
StrStatusBarText = "Restoring database..."
AddStatusBar(0)
AddStatusBar(2)
Me.SbcBackupRestore.Update()
strExec = "RESTORE DATABASE " & DatabaseName & " FROM
DISK = '" & FileName & "' WITH REPLACE, MOVE '" & strDatFile & "' TO '" &
strDataPath & DatabaseName & ".mdf', MOVE '" & strLogfile & "' TO '" &
strDataPath & DatabaseName & ".ldf'"
strquery = strExec
Call MyDataAccess.ExecuteUpdateStatement(strquery, GblConnectionString2)
 
Ad

Advertisements

G

Guest

Hi Ken,
I tried the application.doevents but unfortunately it didn't seem to
make any difference. The Progress bar appears on the screen but the progress
bars to not get added.

When I look at the output window the following messages appear

15
***** B4 adding 1 to the bar value = *******
16
etc etc.

This indicates that whilst the restore query is been carried out the debug
messages after the bar.Value += 1 are not been written. Any ideas would be
greatly appreciated.

Regards
Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top