如何限制并行循环运行。使用vb.net? [英] How to restrict randomly loop running in Parallel.For using vb.net?

查看:82
本文介绍了如何限制并行循环运行。使用vb.net?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何限制在Parallel中运行的随机循环。使用vb.net?

是否有任何选项可用按顺序运行'0'索引到'N'索引。



示例:

数组列表包含10个项目,总计数为10.

和使用并行。 for循环逐个执行,



性能导向这个功能非常好,所以我想克服正常for循环到Parallel.For循环。



实际Parallel.For循环输出为:

Hi,

How to restrict the randomly loop running in Parallel.For using vb.net?
Is any option is available to run '0'-th index to 'N'-th index sequentially.

Example:
Array List having 10 items, its total count as 10.
and Using Parallel.for loop execute one by one random wise,

Performance oriented this feature is very good, so I want overcome normal for loop to Parallel.For loop.

Actual Parallel.For loop output is:

Output: 1,5,2,7,0,3,8,4,9,6.





我想像往常一样逐个执行值For循环。



I want to execute value one by one like normal For loop.

Output: 0,1,2,3,4,5,6,7,8,9.



如果可用,那么用于处理此问题的函数。




If available, then which function used to handle this.

.

推荐答案

你在说什么是循环的第二次迭代可以与第一次迭代并行,但它必须等到第一次完成...

通过设计并行循环定义的顺序输出没有意义......所以你要求的是不可能的......

还要记住,并行总是比顺序表现更好......
What are you saying is that the second iteration of the loop can start parallel with the first but it have to wait to finish for the first...
By design parallel loops define that the order of the output has no significance...So what you ask for is not possible...
Also remember that parallel no always perform better than sequential...


这篇关于如何限制并行循环运行。使用vb.net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆