RadProgressBar not updating on async methods

4 posts, 0 answers
  1. Amine
    Amine avatar
    2 posts
    Member since:
    Apr 2014

    Posted 26 Nov 2015 Link to this post

    iam trying to upload some file on a server and i did it async it works just fine but i want to show the progress of the uploading on progress bar that i embed in a listview using this thread

    i update the progress bar value on event progresschanged that i create for uploading this is the code am using

    UploaderService ser = new UploaderService();
    radListView1.Items.Add("1", "Test Video", "", "", 0, "");
    ser.Authenticate("username", "password");
    Uploader up = new Uploader(ser, @"C:\Users\public\Downloads\Video\E");
    up.ProgressChanged += ((ss, rr) =>
    {
        var PercentComplete = (rr.Progress * 100.0f) / up.Size;
        radListView1.Items[0][4] = Convert.ToInt32(PercentComplete);
    });
    i tried the updatelayout methode and Application.DoEvents() also the refresh, and to let you know its on the  radform thread and i make it work only on runtime by clicking on the headercell and its update the progress bar

     also i found a workaround but theres any other way withou making a loop while

    while (true)
    {
        var PercentComplete = (up.Progress * 100.0f) / up.Size;
        radListView1.Items[0][4] = Convert.ToInt32(PercentComplete);
        radListView1.RootElement.UpdateLayout();
        radListView1.Refresh();
        if (PercentComplete == 100)
        {
            break;
        }
    }

  2. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 27 Nov 2015 Link to this post

    Hi Amine,

    In Windows Forms, controls can be safely accessed only from the thread on which they were created on: Make Thread-Safe Calls to Windows Forms Controls. Please find below my code snippet for updating a progress bar from another thread: 
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
     
        private void radButton1_Click(object sender, EventArgs e)
        {
            this.UpdateFromAnotherThread();
        }
     
        private void UpdateFromAnotherThread()
        {
            Thread backgroundThread = new Thread(
               new ThreadStart(() =>
               {
                   for (int n = 0; n < 100; n++)
                   {
                       Thread.Sleep(50);
                       this.radProgressBar1.BeginInvoke(
                           new Action(() =>
                           {
                               this.radProgressBar1.Value1 = n;
                           }
                       ));
                   }
     
                   MessageBox.Show("Thread completed!");
                   this.radProgressBar1.BeginInvoke(
                       new Action(() =>
                       {
                           this.radProgressBar1.Value1 = 0;
                       }
                   ));
               }
               ));
     
            backgroundThread.Start();
        }
    }

    I am also sending you a gif file showing the result on my end.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Amine
    Amine avatar
    2 posts
    Member since:
    Apr 2014

    Posted 27 Nov 2015 Link to this post

    the class that am using to embed a progress bar in a cell on a listview they use RadProgressBarElement and not RadProgressBar, as a result i cant find the BeginInvoke() method. i tried to change the RadProgressBarElement  with RadProgressBar but it does not embed progress bar in a cell on a listview
    public class ProgressBarCellElement : DetailListViewDataCellElement
        {
            private RadProgressBarElement progressBar;
     
            public ProgressBarCellElement(DetailListViewVisualItem owner, ListViewDetailColumn column)
                : base(owner, column)
            {
     
            }
     
            protected override void CreateChildElements()
            {
                base.CreateChildElements();
     
                this.progressBar = new RadProgressBarElement();
                this.progressBar.StretchHorizontally = this.progressBar.StretchVertically = true;
     
                this.Children.Add(this.progressBar);
            }
     
            public override void Synchronize()
            {
     
                base.Synchronize();
                this.Text = "";
                try
                {
                    this.progressBar.Value1 = Convert.ToInt32(this.Row[this.column]);
                }
                catch { }
     
            }
     
            protected override Type ThemeEffectiveType
            {
                get
                {
                    return base.ThemeEffectiveType;
                }
            }
        }
  5. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 30 Nov 2015 Link to this post

    Hello Amine,

    Thank you for writing.

    As I understand from your other forum post you are working on the UI thread and hence your issue does not appear to be related with multithreading. In order to reflect changes between your business objects and the control, my suggestion is that you create a model object implementing the INotifyPropertyChanged interface.

    I am sending you an example project demonstrating how this can be achieved as well as a gif file showing the result on my end.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top