LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Decrease the CPU uasge in CVI(6.0) programming

Hello,

In my GUI , there are just only 2 buttons,but I found when moving the mouse , the CPU usage will increase very large , how to shield the unwanted mouse moving event ? because I am afraid which will interfere the sampling process from a real-world device . Thanks.

David
0 Kudos
Message 1 of 2
(2,958 Views)
One way to minimize cpu usage is to make sure that the CVI Sleep policy is set to sleep more. You can do this by going to the project window, Options >> Environment, and selecting sleep more from the top pull down menu.

When you're inside RunUserInterface, the CVI run-time engine is in a continuous loop, peeking for system events. CVI needs to process and dispatch these events, in order to maintain its internal state 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).

Another thing you could do is replace RunUser
Interface() with a while loop that run ProcessSystemEvents() and has a sleep set for a certain time period, something like the following

#include // for the Sleep function

int gQuit = 0; // global flag that should be set when calling QuitUserInterface

while (!gQuit) {
ProcessSystemEvents ( );
Sleep (10);
}

This should bring the CPU usage down as well.

I hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
Message 2 of 2
(2,958 Views)