.net ComponentOne RibbonButton由后台工作程序调用
我试图在后台工作程序完成时更改C1功能区按钮的SmallImage属性 问题是我得到了“跨线程操作无效:从创建控件的线程以外的线程访问控件'MyControl' 我通过检查Windows控件上的InvokeRequired解决了其他跨线程问题,但是ComponenetOne控件没有InvokeRequired属性 通过研究,我认为在progresschanged事件中访问控件图像属性可以解决这个问题。以下是相关代码。doWork和progresschanged事件都在工作线程上运行,因此我仍然遇到了跨线程问题。有没有人能看出我做错了什么,或者有没有其他方法可以解决这个问题.net ComponentOne RibbonButton由后台工作程序调用,.net,backgroundworker,componentone,.net,Backgroundworker,Componentone,我试图在后台工作程序完成时更改C1功能区按钮的SmallImage属性 问题是我得到了“跨线程操作无效:从创建控件的线程以外的线程访问控件'MyControl' 我通过检查Windows控件上的InvokeRequired解决了其他跨线程问题,但是ComponenetOne控件没有InvokeRequired属性 通过研究,我认为在progresschanged事件中访问控件图像属性可以解决这个问题。以下是相关代码。doWork和progresschanged事件都在工作线程上运行,因此我仍然遇
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();
...
}
您没有从启动backgroundworker的位置发布代码,但是如果您的progresschanged事件正在编组到工作线程。这意味着您从另一个线程开始工作,然后是主线程。后台工作程序捕获同步上下文(SynchronizationContext),从该上下文开始对progresschanged和runworkercompleted事件中的调用进行马歇尔处理。您是否尝试过检查控件容器(可能是表单)的
InvokerRequired
属性,我在想办法解决这个问题,因为似乎没有其他人能提供帮助。但感谢您的回复。