简体   繁体   中英

Real Time priority in .Net

I have an application that feeds audio data to a FTDI device via the D2XX interface. It works perfectly while my application has focus, and uses very little 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.

I tried many things to prevent this (Process/Thread priorities to real-time, MMCSS scheduling, etc), but it still occurs sometimes.

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. 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. When you create a task factory and let the work be done by several parallel threads, the assigned cpu % will be higher.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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