I've eradicated fungus gnats in my enclosures by treating all my substrate by using boiling water, vacuuming any loose adults flying about, and re-potting my houseplants with heat-treated substrates. Just make sure to cover your enclosures to make sure adults can't get into your clean substrate before you've eliminated them all from the room and house. Once they're gone from the enclosures and from your home, you're unlikely to see them return unless you bring them in from outside. If you allow them to continue breeding by ignoring them, there's always the chance of one egg-laden female getting into your other enclosures. Common sources of fungus gnats are compost bins, trash bins, and the potting substrate of house plants.
In my experience, drying the substrate can reduce the population, but they'll continue to successfully reproduce. Dry ice is also not a effective method of exterminating fungus gnats since many soil organisms can tolerate low oxygen levels for some time and because there will be pockets of oxygen within the soil where the carbon dioxide will not penetrate.