限制每个时间单位的迭代次数 [英] Limit iterations per time unit

查看:184
本文介绍了限制每个时间单位的迭代次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法限制每个时间单位的迭代?例如,我有一个这样的循环:

Is there a way to limit iterations per time unit? For example, I have a loop like this:

for (int i = 0; i < 100000; i++)
{
    // do stuff
}

循环,所以每秒最多有30次迭代。

I want to limit the loop above so there will be maximum of 30 iterations per second.

我也希望迭代在时间轴上平均放置,所以不像第一次迭代30次然后等待0.6秒。

I would also like the iterations to be evenly positioned in the timeline so not something like 30 iterations in first 0.4s and then wait 0.6s.

这是可能吗?

推荐答案


@FredOverflow我的程序运行
非常快。它通过
wifi发送数据到另一个程序,不是
足够快速处理它们在
当前费率。 - Richard Knop

@FredOverflow My program is running very fast. It is sending data over wifi to another program which is not fast enough to handle them at the current rate. – Richard Knop

然后你应该可以让你发送数据的程序在收到最后一块您发送的数据然后发送下一个块。其他任何事情只会导致你的沮丧下来的情况变化。

Then you should probably have the program you're sending data to send an acknowledgment when it's finished receiving the last chunk of data you sent then send the next chunk. Anything else will just cause you frustrations down the line as circumstances change.

这篇关于限制每个时间单位的迭代次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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