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

RadStatusStrip's RadLabelElement & Backgroundworker Question.

3 Answers 8 Views
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 2
Veteran
Mark asked on 14 Nov 2017, 09:41 PM

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

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 15 Nov 2017, 08:43 AM
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.
0
Mark
Top achievements
Rank 2
Veteran
answered on 15 Nov 2017, 01:24 PM

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.

 

 

0
Dimitar
Telerik team
answered on 16 Nov 2017, 10:23 AM
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.
Asked by
Mark
Top achievements
Rank 2
Veteran
Answers by
Dimitar
Telerik team
Mark
Top achievements
Rank 2
Veteran
Share this question
or