Hi. For sure not only I have a problem with using these prepositons. Some useul tips:
"WHEN" - it is used when we want to say about a short operation that interrupted another activity - longer or takes an approximate time to the main activity. When we are talking about periods of life. The examples:
1. I was driving a car when I saw Tim.
2. He was reading book when the bell rang.
"WHILE" - it is used for two long activities that take place simultaneously. The examples:
1. It was raining while I was riding a bike.
2. I saw my friend while I was buying some books.
It would be nice If could give other examples.
<a href="https://www.italki.com/user/4274409">Hi Jackie Carey</a>
Thanks for your comment.