There is a difference in the usage of the two words (when and while). The former (when) is used to give details on the time of an event or action.
Example: Insert a coin when the light comes on. / When the light comes on, insert a coin.
The time to perform the inserting action is the moment the light comes on.
The latter (while) is used to describing two actions happening at the same time.
Example: While they were boarding the bus, the door closed.
(Notice that the verb in continuous tense "boarding" is the first action, while the verb in simple past tense "closed" is the second action that interrupted the first action.)
Hope this helps.