I haven't clicked hamsterman's link yet, you should if you haven't already, but I wanted to point out that your while loop will spike the CPU and the only thing it is doing is checking that condition much more often then needed.
What libs are you using? We might have a better solution in one of those for what you are trying to accomplish.