无限循环会消耗100%的CPU [英] Infinite looping consumes 100% CPU

查看:228
本文介绍了无限循环会消耗100%的CPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我陷入了需要产生一定Hz定义频率的情况.我已经尝试了多媒体计时器和Internet上所有其他可用的东西,但是到目前为止,如果有其他条件的无限循环给了我最好的结果.但是这种方法的问题在于,它消耗了几乎所有的cpu,没有空间让其他应用程序正常工作.

I am stuck in a situation where I need to generate a defined frequency of some Hz. I have tried multimedia timers and all other stuff available on the internet but so far an infinite loop with some if-else conditions gave me the best results. But the problem in this approach is that it consumes almost all of the cpu leaving no space for other applications to work properly.

我需要一种算法,该算法可以生成从Hz到KHz的频率.

I need an algorithm with either generates frequency of some Hz to KHz.

我正在Windows平台上使用C#.

I am using windows plateform with C#.

推荐答案

您无法在非实时平台上准确生成固定频率的信号.任何时候,来自同一进程或其他进程的高优先级线程都可能阻止线程的执行.例如.当GC线程启动时,辅助线程将被挂起.

You can't accurately generate a signal of a fixed frequency on a non-realtime platform. At any moment, a high priority thread from same or other process could block the execution of your thread. E.g. when GC thread kicks in, worker threads will be suspended.

话虽这么说,您被允许的抖动是多少?需要支持的最高频率是什么?

That being said, what is the jitter you are allowed to have and what is the highest frequency you need to support?

这篇关于无限循环会消耗100%的CPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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