Neither of these is a well-formed, complete sentence.
________
The first (when going to a party) means it becomes dangerous to go to a party, it's time to think seriously about the situation.
________
The second (when to go to a party) means the time at which you go to a party.
It's a...