This suggests to me you might be overflowing the MIDI buffer on your PC and the USB linkage is what is crashing.

EDIT - looks like you are sending messages on every loop. You need to send only if...