Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 并行问题:跨线程操作无效:从创建控件的线程以外的线程访问控件_Multithreading_Parallel Processing - Fatal编程技术网

Multithreading 并行问题:跨线程操作无效:从创建控件的线程以外的线程访问控件

Multithreading 并行问题:跨线程操作无效:从创建控件的线程以外的线程访问控件,multithreading,parallel-processing,Multithreading,Parallel Processing,我有一个简单的代码: Parallel.Invoke( () => picturebox_1.Refresh(), () => picturebox_2.Refresh()); 我明白了: 跨线程操作无效:从创建控件的线程以外的线程访问控件 我如何解决这个问题?我只想并行运行刷新,刷新方法运行Paint事件,该事件包含渲染图像的代码 谢谢 必须使用UI线程进行调用,不能在创建的线程上更新UI,

我有一个简单的代码:

 Parallel.Invoke(
                        () => picturebox_1.Refresh(),
                    () => picturebox_2.Refresh());
我明白了:

跨线程操作无效:从创建控件的线程以外的线程访问控件

我如何解决这个问题?我只想并行运行刷新,刷新方法运行Paint事件,该事件包含渲染图像的代码


谢谢

必须使用UI线程进行调用,不能在创建的线程上更新UI,必须使用forms invoke方法或控件

因此,ui操作无法并行化,因为ui只在一个线程中运行。为什么要并行刷新?我之所以要并行刷新,是因为我可以同时刷新两个控件,而不是一个接一个地刷新。。我想我可以通过这样做获得一些表现?