They can have the same meaning if one or both of the actions is/are long. However, if both actions are short, we use "when." e.g. When/While I was eating dinner, I was watching TV. When/While I was watching TV, I threw up! When I threw up, I dropped my fork.
when+ s.present tense / s.past are correct but when + past continuous tense is INCORRECT .. and also WHILE + PAST CONTINUOUS TENSE IS CORRECT BUT WHILE + S. PAST TENSE IS INCORRECT.. 3- While I was watching TV, the electricity went off.
4- when the electricity went off, I was studying Organic Chemistry.