Sam took a photograph of me when/ while I was not looking.
It would be appreciated if someone please shine a light in if there is any difference between the two.
She took a photograph of me when/while I was not looking.
The words "while" and "when" are also used as conjunctions in subordinate clauses to express time. When used so, it means "during the time that something else happens". The while-clause is usually progressive or gives the sense of the duration or continuity of some action.
On the other hand, the conjunction "when" is used to mean not only "at the time that something happens (a point in time) but also "during the time that something is happening (while)".
In light of the above definitions, it stands to reason that while and when are interchangeable when you mean to say "during the time that something is happening". So you can use either when or while in the subject sentence. Some more examples are given below:
I read it while/when you were cooking.
The phone rang while/when we were eating dinner.
We went out while/when it was raining.
However, the use of "while" is preferable in such sentences.
Both of them indicate same-time (synchronous) activities, however, there are some differences:
"When isfollowed by a clause with an activity that (1) is a short interruption, or (2) occurs at nearly the same time or shortly after another activity. A nonprogressive verb form is more commonly used (short duration)."
"While is followed by a clause with a same-time (simultaneous) activity and includes a verb expressing duration. The while-clause often expresses a background activity to the focus-activity in the main clause."
Is there a difference between the two in that sentence? - NO.
We use both when and while as subordinating conjunctions to introduce adverbial clauses of time. They mean during the time that and indicate that something is or was happening when something else occurred:
This explanation perfectly fits in the context you described in the sentence. Having said that, there's no difference in using while/when there.