It's hard to answer this without a larger context: both have several uses, some of which are completely separate.
For example, we can use 'while' to mean 'although':
"While I like chocolate, I don't like chocolate cake"
Meanwhile, 'when' can be used as a question word:
"When will you eat chocolate?"
I'm going to assume you're talking about things happening at certain times.
In this case, 'while' means that the two actions are happening at exactly the same time as each other. I can watch TV while I eat, or go out while the weather is nice.
On the other hand, 'when' means that the two actions are happening at very similar times, and suggests there is a relationship between them.
"I like it when you smile" = When I see you happy, I also feel happy (for some time)
"I like it while you smile" (?) = When I see you happy, I am also happy, but as soon as you stop being happy, I stop being happy as well
Sometimes the two can have the essentially same meaning.
"I watch TV while I eat" = "I watch TV when I eat"
In general, it's probably safer to use 'when' instead of 'while', if you can't choose.