...Never write it on purpose. If I ever find myself wondering what the next character to speak is going to say next, I take a break and get a snack, or take a little walk, or go to sleep.
I think the secret to writing dialog is to relax and let the characters have their conversation. If you know your characters, you should have a pretty good idea of how their mind works and what they're going to say or do will just kind of happen.
In the Sexton Chronicles, Andy is the smartass of the characters. There's a pretty good chance he'll come up with a snappy reply to whatever John says--and it's often at John's expense. Andy likes to make fun of John, and say that John isn't funny. He's wrong about that, by the way. Andy is usually too busy trying to make fun of John to notice that John just said something funny. I let them sort it out.
Having a background in theater is the biggest help I have when it comes to dialog, but not in the way you think. Sure, it helps that plays are almost all dialog and that I had the privilege of acting in plays written by some masters of dialog. However, the strength I took from theater in writing dialog has more to do with the ability to get "in character" and think like the character who is speaking. On the stage, that ability helped me ad-lib successfully when the wheels left the rail. I was once accused of ad-libbing in iambic pentameter when I played Macbeth. The accuser was right. I was. It wasn't any sort of ability to place the emphasis on every fifth syllable by instinct (I don't think so, though it could have been) but a matter of not just playing Macbeth, but of being Macbeth.
Similarly, I have been accused of writing great dialog in the Sexton books. I deny the accusation. It's more a matter of letting dialog happen. I don't over-think it. Much like a conversation, I just let the next line happen. Unlike conversation however, I reserve the right to revise it. And the fun is...when I revise it, you, the reader, never know!