When X, Y - X is a single point in time. It's possible and likely that Y interrupted X.
As X, Y - X is a single point in time. It's not likely that Y interrupted X - Y and X happened concurrently.
While X, Y - X is a duration of time, not a single point in time. Y may or may not have interrupted X.
If X requires a lot of time or is a long, continuous activity, while should be used over when.
If Y is not something that requires physical/mental interruption of X, the difference between these doesn't matter very much, but can imply the degree of importance or attention Y has.
When I was walking down the street I saw Joe driving a Porsche (Maybe I stopped walking when I saw him.)
While I was walking down the street I saw Joe driving a Porsche (The walk was a long walk, and maybe it was significant that I saw him driving a Porsche but I might not have stopped in my tracks at that moment.)
As I was walking down the street I saw Joe driving a Porsche (Joe might have been far away and I didn't bother to stop walking.)