As conjunctions, they are used interchangeably in the past tense. However, the general rule is that "while" is used with progressive tenses (ongoing/continuous action) and "when" is used with simple past tense (occurred only in the past).
- "While it was raining..." vs "When it rained..."
- "While I was watching TV..." vs "When I watched TV..."
- "While the phone was ringing.." vs "When the phone rang..."