简体   繁体   English

.Net中的实时优先级

[英]Real Time priority in .Net

I have an application that feeds audio data to a FTDI device via the D2XX interface. 我有一个通过D2XX接口将音频数据馈送到FTDI设备的应用程序。 It works perfectly while my application has focus, and uses very little CPU (5%). 当我的应用程序具有焦点时,它可以完美工作,并且只使用很少的CPU(5%)。 But when I hammer the CPU (by switching to other applications, or heavy drawing) sometimes I can produce a stutter in the audio. 但是当我重击CPU时(通过切换到其他应用程序或进行大量绘制),有时会在音频中产生卡顿现象。

I tried many things to prevent this (Process/Thread priorities to real-time, MMCSS scheduling, etc), but it still occurs sometimes. 我尝试了很多方法来防止这种情况发生(实时的进程/线程优先级,MMCSS调度等),但有时仍然会发生。

Is there any other way left to raise priorities, or is it impossible without writing a kernel driver? 还有其他提高优先级的方法吗?或者不编写内核驱动程序就不可能吗?

If you set your process (not thread) priority to “Realtime”, its threads should be always run before threads from other processes that are not Realtime. 如果将进程(非线程)优先级设置为“实时”,则其线程应始终在其他非实时进程的线程之前运行。 So I think this is the best you can do. 所以我认为这是您可以做的最好的事情。

But you should use the Realtime process priority only when absolutely necessary, because it can cause the whole system to become unresponsive. 但是,仅在绝对必要时才应使用“实时”进程优先级,因为它可能导致整个系统无响应。

Increase priority of the thread that services the device, or increase (if it is possible) buffer size for the communication with the device. 增加服务设备的线程的优先级,或者增加(如果可能)与设备通信的缓冲区大小。

Minimum time of task switching inside windows is 10ms. Windows内任务切换的最短时间为10ms。 If your thread doesn't handle data from the device on time, you'll have stutter and drops in audio. 如果您的线程不能按时处理设备中的数据,则会出现断断续续的声音。

You might want to consider using the parallel programming possibilities of .net 4.0. 您可能要考虑使用.net 4.0的并行编程功能。 When you create a task factory and let the work be done by several parallel threads, the assigned cpu % will be higher. 创建任务工厂并通过多个并行线程完成工作时,分配的cpu%将更高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM