The spell description states it very well when it happens. Here is what the spell says about when it goes off. "In all cases, the contingency immediately brings into effect the second spell, the latter being "cast" instantaneously when the prescribed circumstances occur."
What's that mean? Well...