'when' functions as a subordinate conjunction. If the adverbial clause introduced by 'when' is placed after main clause, you need not a comma. If the adverbial phrase is fronted, you should place a comma before the main clause.Originally Posted by mrgoh
He was reading a book when somebody knocked on the door.
When somebody knocked on the door, he was reading a book.
Somebody knocked on the door while he was reading.
While he was reading, somebody knocked on the door.
I don't see much difference between. Both mean during the time that someone was doing something, another event just happened.