In general, I'd advice you to study exactly when this happens, extract conclusions about the why based on this information.
Try out different things, play with your application. Especially try the things one normally would not do, as these situations are often the ones that generate the unpredicted bugs.
Once the error happens, start your application again and do exactly the same thing - does it generate the error again?
If so, you should now at least have some general idea as to where your code may be wrong.