And what exactly happens when "it stops working"? The program crashes with an error? Turns black? etc.
Also, thats not a complete example. In other words, I can't take the code you posted, run it, and recreate your problem. See if you can make as small of an example as you can that actually runs and reproduces your problem. This can also be a good way to try and debug on your own because it forces you to find the specific part of your program that is causing problems and makes it more obvious what is going wrong.