The code I am having problem with is reading data from a com port at 10x per second. For each com port data an image is captured and a measurement is taking from this image. All these happens in a while loop with 5ms delay. When the program is executed the loop time is about 80ms. What I am seeing is that if the mouse is moved quickly or a web browser is opened or another program is open for that matter, the while loop time spikes to as high as 300ms. On the front panel I have an image, array indicators and two charts.
My question is what is causing this behaviour and what is the best way to prevent? The computer I am using has 4GB of RAM.