This is a migrated thread and some comments may be shown as answers.

PorgressBar Not Updating

2 Answers 538 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Florian asked on 17 Feb 2015, 10:18 AM
Hi all, 

i want to make a ProgressDialog.

User clicks on button "Delete", then ProgressDialog opens and Progress should be shown.

This is my code for the dialog class:

Public Class ProgressDialog
    Public Property MessstelleItems As New List(Of tblMessstelleVerzeichnisNeue)
    Public Property ZahlerItems As New List(Of tblZahler)
    Public Property MessstellenPage As MessstellenPage
    Public Property ZahlerPage As ZahlerPage
    Private _ctx As EnergieManagementDataContext
    Public Sub New(ByVal ctx As EnergieManagementDataContext)
        ' This call is required by the designer.
        _ctx = ctx
        ' Add any initialization after the InitializeComponent() call.
    End Sub
    Protected Overrides Sub OnShown(ByVal e As EventArgs)
    End Sub
    Private Sub DoWork()
        RadProgressBar.Minimum = 0
        If MessstelleItems.Count > 0 Then
            RadProgressBar.Maximum = MessstelleItems.Count
            For Each item In MessstelleItems
                Dim index = MessstelleItems.IndexOf(item) + 1
                ProgressRadLabel.Text = "Lösche Messstelle " + index.ToString() + " von " + MessstelleItems.Count.ToString()
                RadProgressBar.Value1 = MessstelleItems.IndexOf(item) + 1
                Dim tmp As New List(Of tblMessstelleVerzeichnisNeue)
                MessstellenPage.CurrentMeasuringPoints = (From p In _ctx.tblMessstelleVerzeichnisNeues.ToList() Join r In tmp On p.MessstelleVerzeichnisID Equals r.MessstelleVerzeichnisID Select p).Distinct().ToList()
        End If
    End Sub
End Class
The deletion progress works fine. Only the Progressbar isnt displayed.

ProgressDialog is started as a modal Dialog:

Using dataContext = New EnergieManagementDataContext
    Dim dlo As New DataLoadOptions()
    dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblMessstelleVerzeichnisZeiches)
    dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblMessstelleVerzeichnisMessbereiches)
    dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblMessstelleVerzeichnisStorungsbereiches)
    dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblMessstelleVerzeichnisVersionZahlerKanals)
    dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblMessstelleVerzeichnisVersionVerantwortliches)
    dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblMessstelleVerzeichnisAreal)
    dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblDokumentes)
    dlo.LoadWith(Of tblMessstelleVerzeichnisVersionZahlerKanal)(Function(r) r.tblZahlerKanal)
    dlo.LoadWith(Of tblZahlerKanal)(Function(r) r.tblZahlerVersion)
    dataContext.LoadOptions = dlo
    Dim progress As New ProgressDialog(dataContext)
    items = RadGridViewMessstellen.SelectedRows.Select(Function(c) CType(c.Tag, tblMessstelleVerzeichnisNeue)).ToList()
    progress.MessstellenPage = Me
    progress.MessstelleItems = items
End Using

No need to check DialogResult, just for blocking thread stepping out of the using block.

Any suggestions why the ProgressBar isnt updated when function runs. 
When work is completed the RadProgressBar shows the full Progress.


2 Answers, 1 is accepted

Sort by
Top achievements
Rank 1
answered on 19 Feb 2015, 11:34 AM
Found a solution,

After Value1 is set, call Application.DoEvents() this will update ui. this solution helped me too. Worked also with threads.
BackgroundWorker hasn't worked in my case, got some Strange index out of bound exception, but couldn't figure out why it was thrown. So i took first solution.
Telerik team
answered on 19 Feb 2015, 02:16 PM
Hello Florian,

Thank you for writing.

In this case your solution is correct and you should call the Application.DoEvents method.

Here is an example with BackgroundWorker in case you need it:
Public counter As Integer
Private Sub worker_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
    For index As Integer = 1 To 100
        counter += 1
    Next index
End Sub
Private Sub UpdateProgressBar(ByVal newValue As Integer)
    Me.radProgressBar1.Value1 = newValue
    Me.radProgressBar1.Text = "<html><span style=""font-size: 14pt""><strong>" & Me.radProgressBar1.Value1.ToString() & " %</strong></span></html>"
End Sub
Private Sub radButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim worker As New BackgroundWorker()
    AddHandler worker.DoWork, AddressOf worker_DoWork
    Do While ((worker IsNot Nothing) AndAlso worker.IsBusy)
        If Me.radProgressBar1.Maximum >= Me.radProgressBar1.Value1 + counter Then
            UpdateProgressBar(Me.radProgressBar1.Value1 + counter)
            Exit Do
        End If
End Sub

Please let me know if there is something else I can help you with. 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Asked by
Top achievements
Rank 1
Answers by
Top achievements
Rank 1
Telerik team
Share this question