是否有可能一次循环2个项目....? [英] is it possible to loop 2 items at a time ....?

查看:75
本文介绍了是否有可能一次循环2个项目....?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hii,

是否可以在一个tym上循环2个项目或5个项目而不是一个

一个......



i知道这不是一个明显的问题,但我想要专业人士的答案......





thxxxsss .....

hii,
is it possible to loop 2 items or 5 items at a tym instead of one
by one ....

i know this not an obvious question but stell i want an answer from professionals ...


thxxxsss.....

推荐答案

嗯。是的......没有。

如果你有备用核心,那么你可以使用单独的线程同时真正地做很多事情 - 但有多少是不能保证的,并且会有所不同时刻取决于整个系统的负载。真正独立地做事几乎要求任务不是相互依赖的。如果第2项需要来自第1项计算的数据,那么它就变得相当复杂。



如果这会提高性能取决于你需要执行的任务:添加线程会增加它自己的开销,因此不同线程中的许多小操作可能比同一线程中顺序执行的相同操作更慢并且需要更多资源。



但是......首先查看 Parallel.ForEach [ ^ ]和 BackgroundWorker [ ^ ] class - 它们是开始使用它的最简单方法。



但要小心 - 当你启动多线程时会有很多隐藏的复杂性。
Um. Yes...and no.
If you have spare cores, then you can use separate threads to genuinely do a number of things at the same time - but how many is not guaranteed, and will vary from moment to moment depending on the load on the system as a whole. And doing things truly independently requires pretty much that the tasks are not interdependent. If item 2 requires data from item 1's calculations, then it gets pretty complex to work out.

And if this will improve performance depends on the task you need to perform: adding threading adds an overhead of it's own, so a lot of small operations in different threads can be slower and require more resources than the same operations done sequentially in the same thread.

But...start by looking at Parallel.ForEach[^] and the BackgroundWorker[^] class - they are the easiest way to get started with this.

But be careful - there are a lot of "hidden" complexities when you start multithreading.


这篇关于是否有可能一次循环2个项目....?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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