I am trying to change the SmallImage property of a C1 Ribbon Button when a background worker finishes.
The problem is I am getting "Cross-thread operation not valid: Control 'MyControl' accessed from a thread other than the thread it was created on."
I've worked around other Cross-threading problems by checking InvokeRequired on the Windows Control however the ComponenetOne control does not have an InvokeRequired property.
From researching I thought accessing the Controls image property in the progresschanged event would work around the problem. Below is the relevant code. Both the doWork and progresschanged event are run on the Worker thread however so I' still getting the Cross-Threading problem. Can anyone see what I maybe am doing wrong or is there another way I can solve the problem?
private void InitializeBackgroundWorker1()
{
BackgroundWorker1 = new BackgroundWorker();
BackgroundWorker1.DoWork +=
new DoWorkEventHandler(BackgroundWorker1_DoWork);
BackgroundWorker1.RunWorkerCompleted +=
new RunWorkerCompletedEventHandler(BackgroundWorker1_RunWorkerCompleted);
BackgroundWorker1.ProgressChanged +=
new ProgressChangedEventHandler(BackgroundWorker1_ProgressChanged);
BackgroundWorker1.WorkerReportsProgress = true;
}
private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
e.Result = sResult;
(sender as BackgroundWorker).ReportProgress(25);
}
private void BackgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
MyControl1.ribbonButtonStatus.SmallImage = Properties.Resources.trafficlight_green;
}
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
MyControl1 = new TimeGridControl();
...
}