Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/05/2007, 14:05
Avatar de vecasita
vecasita
 
Fecha de Ingreso: abril-2006
Mensajes: 107
Antigüedad: 18 años, 10 meses
Puntos: 1
ProgressBar y BackgroundWorker

Alguen ha tiene un ejemplo de como mostrar el progreso de mediante un ProgressBar mientras se espera el resultado de una consulta a una base de datos ?.
Lo que tengo es un llamado a un Procedimiento almacenado para llenar una grilla, pero con se demora, quisiera que se mostrara en un ProgressBar que la consulta se esta ejecutando..

Encontre el sgte codigo, pero no me funciona ya que me llena el progressbar cuando la consulta esta terminada y no lo va llenando mientras espera...

Public Sub InicioProceso()

_Contador = ProgressBar1.Minimum

Me.Cursor = Cursors.WaitCursor

BackgroundWorker1.WorkerSupportsCancellation = True

BackgroundWorker1.WorkerReportsProgress = True

BackgroundWorker1.RunWorkerAsync()

End Sub

Public Sub FinProceso()

BackgroundWorker1.CancelAsync()

End Sub

Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
While Not BackgroundWorker1.CancellationPending

If Not BackgroundWorker1.CancellationPending Then

If _Contador = ProgressBar1.Maximum Then _Contador = ProgressBar1.Minimum Else _Contador += 1

Threading.Thread.Sleep(10)

BackgroundWorker1.ReportProgress(_Contador, "Guardando...")

Else

e.Cancel = True

Exit While

End If

End While
End Sub

Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub

Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
If Not (e.Error Is Nothing) Then

' There was an error during the operation.

Dim msg As String = String.Format("Error: {0}", e.Error.Message)

MessageBox.Show(msg)

Else

' The operation completed normally.

ProgressBar1.Value = ProgressBar1.Minimum


End If

Me.Cursor = Cursors.Default

ProgressBar1.Value = ProgressBar1.Maximum

End Sub


alguna idea ?

Gracias.