Concept:The pair "hardly...when" connects two events that happen almost at the same time.
Explanation:The sentence starts with "hardly," so it requires the correlative conjunction "when" in the second part.
This structure means that as soon as the teacher turned his back, the class became noisy.
Option A "than" is used after "rather" or comparatives, not "hardly."
Option C "then" does not fit the pattern "hardly...when."
Option D "hence" expresses a result, not an immediate sequence.
Therefore, the correct word is "when."
Answer:B. when