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

PorgressBar Not Updating

2 Answers 608 Views
ProgressBar
This is a migrated thread and some comments may be shown as answers.
Florian
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.
        InitializeComponent()
        _ctx = ctx
        ' Add any initialization after the InitializeComponent() call.
 
    End Sub
 
    Protected Overrides Sub OnShown(ByVal e As EventArgs)
        MyBase.OnShown(e)
        DoWork()
    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
                Me.Refresh()
 
                Dim tmp As New List(Of tblMessstelleVerzeichnisNeue)
                tmp.Add(item)
                MessstellenPage.CurrentMeasuringPoints = (From p In _ctx.tblMessstelleVerzeichnisNeues.ToList() Join r In tmp On p.MessstelleVerzeichnisID Equals r.MessstelleVerzeichnisID Select p).Distinct().ToList()
                MessstellenPage.DeleteCurrentMeasuringPoints()
 
            Next
 
        Else
 
        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
    progress.ShowDialog()
 
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.

thx

2 Answers, 1 is accepted

Sort by
0
Florian
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.

http://www.telerik.com/forums/radprogressbar-and-waiting-status 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.
0
Dimitar
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
        Thread.Sleep(1000)
    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>"
    Me.radProgressBar1.Invalidate()
    Application.DoEvents()
    Thread.Sleep(1000)
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
    worker.RunWorkerAsync()
 
    Do While ((worker IsNot Nothing) AndAlso worker.IsBusy)
        If Me.radProgressBar1.Maximum >= Me.radProgressBar1.Value1 + counter Then
            UpdateProgressBar(Me.radProgressBar1.Value1 + counter)
        Else
            UpdateProgressBar(Me.radProgressBar1.Maximum)
            Exit Do
        End If
    Loop
End Sub

Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Telerik
 

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.

 
Tags
ProgressBar
Asked by
Florian
Top achievements
Rank 1
Answers by
Florian
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or