Often these words may be interchangeable, but they carry subtle differences.
We can use while to talk about two longer events or activities happening at the same time.
We can use when to introduce a single completed event that takes place in the middle of a longer activity, such as an interruption. Eg. He was running when the car backfired and gave him a fright.
Student or Learner