RadStatusStrip's RadLabelElement & Backgroundworker Question.

4 posts, 0 answers
  1. Mark
    Mark avatar
    130 posts
    Member since:
    Oct 2014

    Posted 14 Nov 2017 Link to this post

    I was under the assumption that any UI element you wanted to update from the Backgroundworker had to be in the ProgessChanged event. However, I have noticed, only by accident, that I have been able to update the RadLabelElement's Text property w/ in the BackGroundWorker DoWork event.  Is this by design?  I have not been able to find any documentation on this related to the RadLabelElement.

     

    TIA

  2. Dimitar
    Admin
    Dimitar avatar
    2951 posts

    Posted 15 Nov 2017 Link to this post

    Hi Mark,

    In general, you should not update the controls from other than the UI thread. Even that this appears to work it can cause intermittent exceptions. Detailed information is available here: C# Corner: Multithreading in WinForms.

    Here is an example of using a progress bar with BackgroundWorker:
    BackgroundWorker worker = new BackgroundWorker();
    public RadForm1()
    {
        InitializeComponent();
        worker.WorkerReportsProgress = true;
        worker.DoWork += Worker_DoWork;
        worker.ProgressChanged += Worker_ProgressChanged;
    }
     
    private void Worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        radProgressBar1.Value1 = e.ProgressPercentage;
        radProgressBar1.Text = e.ProgressPercentage + "%";
    }
     
    private void Worker_DoWork(object sender, DoWorkEventArgs e)
    {
        for (int i = 0; i <= 100; i++)
        {
     
            worker.ReportProgress(i);
     
            System.Threading.Thread.Sleep(100);
        }
    }
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        worker.RunWorkerAsync();
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Mark
    Mark avatar
    130 posts
    Member since:
    Oct 2014

    Posted 15 Nov 2017 Link to this post

    Dimitar

     

    Yes, I understand that, as I posted in my comments.  I was just wondering if updating the radLabelElement.text property of a radstatusstrip in the DoWork event of a background worker was allowable by design?  We are using the ProgressChanged event to update that object, but before we did, we just updated it from the DoWork event with out any issues.  

     

    Again, thanks for the help.

     

     

  4. Dimitar
    Admin
    Dimitar avatar
    2951 posts

    Posted 16 Nov 2017 Link to this post

    Hello Mark,

    This is not allowed by design and you should update the controls from the UI thread only. It may appear to work but can cause unexpected issues.

    Do not hesitate to contact us if you have other questions.
     
    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top