D
David
I have a .NET 3.0 (VS2005) Winform app. The UI invokes a long-running BRL
process (synchronously, on the same thread). The BRL raises events
periodically to tell the UI to update a progress bar. Works OK, most of the
time. But if the user does something as simple as clicking on the form, the
update of the progress bar stops.
I found that calling DoEvents (rather than just doing a Refresh) in the
event handler that updates the Progress bar "fixes" the problem. But I've
read posts saying that DoEvents is evil. And I can see why. But simply doing
a Refresh in my event handler doesn't suffice. So is there another way ?
(short of reworking the app to run the BR process on a separate
thread...which introduces a different can of worms)
Here's the event handler in the UI which exhibits the problem.
Private Sub ProgressEventRaised(ByVal sender As Object, ByVal e As
ProgressEventArgs)
If e.recordsProcessed > Me.uiProgressBar.Maximum Then
Me.uiProgressBar.Value = Me.uiProgressBar.Maximum
Else
Me.uiProgressBar.Value = e.recordsProcessed
End If
Me.Refresh
End Sub
===> Replacing Me.Refresh with Application.DoEvents "fixes" it. <===
BTW: testing InvokeRequired and re-invoking the event handler doesn't fix
the problem either:
If Me.a-control-on-the-form.InvokeRequired Then
Dim d As New ProgressEventCallback(AddressOf
ProgressEventRaised)
Me.Invoke(d, New Object() {sender, e})
Exit Sub
End If
But since my UI and BR code is running on the same thread, I would have been
surprised if doing this helped.
TIA !
process (synchronously, on the same thread). The BRL raises events
periodically to tell the UI to update a progress bar. Works OK, most of the
time. But if the user does something as simple as clicking on the form, the
update of the progress bar stops.
I found that calling DoEvents (rather than just doing a Refresh) in the
event handler that updates the Progress bar "fixes" the problem. But I've
read posts saying that DoEvents is evil. And I can see why. But simply doing
a Refresh in my event handler doesn't suffice. So is there another way ?
(short of reworking the app to run the BR process on a separate
thread...which introduces a different can of worms)
Here's the event handler in the UI which exhibits the problem.
Private Sub ProgressEventRaised(ByVal sender As Object, ByVal e As
ProgressEventArgs)
If e.recordsProcessed > Me.uiProgressBar.Maximum Then
Me.uiProgressBar.Value = Me.uiProgressBar.Maximum
Else
Me.uiProgressBar.Value = e.recordsProcessed
End If
Me.Refresh
End Sub
===> Replacing Me.Refresh with Application.DoEvents "fixes" it. <===
BTW: testing InvokeRequired and re-invoking the event handler doesn't fix
the problem either:
If Me.a-control-on-the-form.InvokeRequired Then
Dim d As New ProgressEventCallback(AddressOf
ProgressEventRaised)
Me.Invoke(d, New Object() {sender, e})
Exit Sub
End If
But since my UI and BR code is running on the same thread, I would have been
surprised if doing this helped.
TIA !