LabWindows/CVI Code Runs Faster When NI MAX Is Opened

Updated Aug 28, 2020

Reported In


  • LabWindows/CVI
  • Measurement & Automation Explorer (MAX)

Issue Details

I have noticed that when I run my LabWindows/CVI code with NI MAX already opened in the background, my application runs faster than it usually does. How can I get my code to execute this fast without having to open NI MAX?  


If you are using NI instruments, such as digital multimeters, function generators, and oscilloscopes, the fetching process will attempt to sleep for 1 millisecond at a time if data is not available. The default system clock resolution on the test system is 10 milliseconds, meaning that a 1 millisecond sleep may take 10 milliseconds instead. I/O Trace and NI MAX configure the system clock resolution to 1 millisecond, so this explains the difference in performance. 


One workaround is to configure the system clock resolution in the CVI application by adding the following code:

#include "windows.h"
const uint32_t desiredTimerResolutionInMilliseconds = 1;
TIMECAPS timeCaps = {0,0};
timeGetDevCaps(&timeCaps, sizeof(timeCaps));
uint32_t timerResolutionInMilliseconds = min(max(timeCaps.wPeriodMin, desiredTimerResolutionInMilliseconds), timeCaps.wPeriodMax);
[Insert Application Logic Here]

Additional Information

The resolution of sleep depends on the resolution of the system clock, which is globally configured. The selected system clock resolution can be observed using Sysinternals tool ClockRes [External Link].