LabWindows™/CVI™ Application Railing CPU

Updated May 11, 2018

Reported In


  • LabWindows/CVI 2015 Base
  • LabWindows/CVI 2015 Full


LabWindows™/CVI 2015

Issue Details

I've noticed that if I move my mouse around my user interface when my LabWindows/CVI application is running, the CPU usage jumps up to 100%. I'm not even clicking on anything when this happens. How can I reduce my CPU usage?


  1. Keep the Sleep policy as Sleep More.
    • To set this sleep policy, call the SetSleepPolicy() function in the main function before RunUserInterface().
    • This reduces the frequency that the program checks for events on the user interface, but background operations run at the same speed.
  2. ​Use ProcessSystemEvents() in a while loop instead of RunUserInterface().
    • When you call ProcessSystemEvents(), LabWindows/CVI runs a fixed number of modified, smaller iterations, during which it also sleeps according to the sleep policy.
    • This method should take less time and is still very sensitive to the sleep policy

Additional Information

The main difference between ProcessSystemEvents() and RunUserInterface() is that RunUserInterface() is more sensitive to the number of events happening on the system. An example implementation is:

#include <windows.h> // for the Sleep function

int gQuite = 0; // set this global flag when calling QuitUserInterface()

while (!gQuit)
     Sleep (10);

This should help reduce CPU usage significantly.

When you're inside RunUserInterface(), the LabWindows/CVI Run-time Engine is in a continuous loop, peeking for system events. LabWindows/CVI needs to process and dispatch these events in order to maintain its internal state as valid. Every time through this loop, we sleep in accordance with the user's sleep policy. This loop is what causes the CPU time to be high, although the more you sleep, the lower the time usage is. Also, the more events we receive, the higher the CPU time (hence the increase when the mouse moves).

Here are some other topics you that some people reference when trying to reduce CPU usage:
  1. ProcessDrawEvents() - This should have virtually no impact on CPU usage.
  2. Single threading vs. multiple threads should have little to no effect on CPU usage.
  3. Debug vs. release configurations should have no effect.
LabWindows/CVI is a bit unusual in how it processes events, and that makes it appear to use a lot of the CPU. Unfortunately, this is part of the core design and cannot be changed easily. However, this is mostly a problem of perception. Our CPU usage is only an issue if no other process is completing for the CPU, because if it is, we yield control.


Not Helpful