while vs when

Since my school days, I have been taught that
while ( past continuous), (past simple)
when( past simple), (past cintinuous)

so, what is the difference between the following sentences:

While I was working in the garden,I hurt my back.
Tom burnt his hand when he was cooking the dinner.

And why don’t we say " …while he was cooking the dinner."

They arrived while we were having dinner. While she was asleep, thieves broke in and stole her handbag. She met Andy while working on a production of Carmen.
Why not? :slight_smile: