Keep the soil as dry as possible. The gnat larvae live in the uppermost portion of the soil. If they are deprived of moisture they will die. The winged adults die of "old age" in about a week. The key is to treat the larvae in the soil.
If you are having a persistent problem, there is a good chance you are introducing the problem with the potting mix that you use.