We had an underground fence for years and trained four of our dogs to it. It worked really well, but training is important ... teaching the dog to turn around and come back into the yard when s/he hears the beep. Leave the flags in place for as long as you need to. For deaf dogs, leave the flags indefinitely. Our neighborhood had these kinds of fences in a lot of yards. Only one dog would repeatedly take the shock or run through the fence, a golden retriever who couldn't stand to have another dog pass his yard. For that one dog, the fence was a bad idea. For all the others (a dozen or more) in the neighborhood, they worked great.
FWIW, the greyhound rescue groups in this area wouldn't adopt out dogs to homes with these kinds of fences, because they could run through them so fast while chasing small animals.
Also, it's never safe to leave a dog alone outside in a yard with an underground fence, because other animals can get in.