LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

GetUserEvent slows down loop unless I move the mouse

This is not critical to my application but I noticed this and I'm curious if: 1) it is normal, 2)what causes this.

I've attached example code that shows this problem.

The setup is really simple. I have a loop that simply counts to 100 when I press the 'Go' button. Inside the loop I use GetUserEvent to check if the 'Abort' button is pressed. If it is pressed then I abort the loop. I also time the whole thing.

If I press 'Go' and leave everything alone it takes about 3 seconds to complete. If I press 'Go' then move the mouse it completes imediately say < 25 milliseconds. Without the GetUserEvent call it completes immediately.

Is this a bug or just the way GetUserEvent works?

I'm using CVI 5.5.1
and WinXP

David Clark
Software Design Engineer
C&H Technologies, Inc.
0 Kudos
Message 1 of 3
(2,932 Views)
Yes, I can explain it. CVI has a sleep policy that effects things like this. It does this in order to take less of the CPU processor time unless it is needed. You can set the sleep policy with the SetSleepPolicy function. In general, the way our sleep policy works is that in the default "Sleep More" state, it peeks for mouse events and system events going on in CVI, and if there are none is sleeps some to give time back to the OS for other applications. So what is happening is, your application sees NO interaction going on with the application (no mouse activity, no system messages, etc.) so it gives time back to the OS.

You will notice that if you set the sleep policy to Do Not Sleep, then you will see consistent and very fast performance regardless of
mouse activity.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 3
(2,931 Views)
Yes, I can explain it. CVI has a sleep policy that effects things like this. It does this in order to take less of the CPU processor time unless it is needed. You can set the sleep policy with the SetSleepPolicy function. In general, the way our sleep policy works is that in the default "Sleep More" state, it peeks for mouse events and system events going on in CVI, and if there are none is sleeps some to give time back to the OS for other applications. So what is happening is, your application sees NO interaction going on with the application (no mouse activity, no system messages, etc.) so it gives time back to the OS.

You will notice that if you set the sleep policy to Do Not Sleep, then you will see consistent and very fast performance regardless of
mouse activity.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 3 of 3
(2,932 Views)