We suffered a prolonged invasion of gnats during the latter half of summer and early autumn this year, presumably because of recurring minor flooding in the basement from using the washer and a pipe drainage issue. They were so numerous and terrible during the worst of it, especially before I surmised the intermittent flooding was attracting them and then took action.
Generally, unless you can seal off all avenues of infiltration and remove/destroy all attracting things, or use a repellant tactic such as a product or routine exterminator visits, you will have to wage a war of attrition on those that are there and will come in, so their numbers don't steady build above a few in any given room on any given time- and also to exorcise your abode of these infernal bastards more quickly if a massive invasion occurs. This war should be prosecuted with constant passive methods (as in, you don't have to do more than set it up and leave, as opposed to spraying them with pesticides or isopropyl as you see them, or the nuclear tactic called fumigation). As they are attracted to windows during daytime and are either more active naturally during midday or are stimulated by light (or both), window strips such as the Catchmasters is one indispensible core method, especially within rooms you primarily use that are being significantly invaded.
The other entails the use of attractants paired with an ensnarer at locations which either are far away from windows and/or are an area they like to congregate. This device alone sans the use of bait doubles as attractant (the yellow color) and ensnarer (adhesive is on the yellow rod part) and is marketed as both. However, you may add bait to it as well to potentiate the attractant effect. Enduring blitzkriegs from these hated creatures every few days and being driven almost insane by the constant annoyance and having to alter my eating habits, I ordered these and prayed for deliverance from my insectoid nemesis (well, desperately hoped would be a better word- I'm an ardent atheist).
These worked so well. On one particularly bloody day, over the 12 hours following the placement of one baton in my room paired with an attractant, the thing had caused terrible carnage in their ranks all by itself. 100-200 were consigned to death, and I found the nearly innumerable black spots peppering the device to be simultaneously disgusting and galvanizing. Very few to none of these things can escape once they land on the yellow surface.
I found these to be useful in the kitchen (two hung from the window curtain rod), adjacent dining area, and downstairs where the gnats seemed to largely congregate and be almost always present (we have refrigerators and freezers down there, and they'd always fly in after we opened the door, leaving some number of them for us to find on the shelves or floor of the units every day after being trapped and soon perishing from hypothermia). Downstairs and the dining room were the best places, especially downstairs, as the repellants made IIRC by the same company completely lost effectiveness within a week, and downstairs was likely where they were invading from and where the attracting factor(s) was.
I wholeheartedly recommend these along with a highly rated brand of window fly strips, as well as homemade inexpensive devices (plastic cups, dish soap, red wine or apple cider vinegar are the products needed for the standard basic type) that work using the same principles and modes of action that these do (attraction and ensnarement). They can be hung from a rod or whatever, or rested on a surface either longways or straight up (use mounting putty for the latter to secure it, though if it falls over, it won't get adhesive on anything if no other objects are near it).
Do be mindful of valuable items like treasured clothing when you deploy and maneuver/work very close to these. The adhesive is soft, thick, and goopy, which means minor contact won't make the device stick to you much as you pull away, but it will come off onto you and potentially ruin or mar items such as clothes (an adhesive dissolver such as Goo-Be-Gone or whatever might resolve it- or maybe ruin it more) which can't be easily washed and is pourous. That said, these are a FAR MORE elegant and useful solution than the more primitive and rudimentary variant of this type known as fly ribbons/paper.
Also, I did not find their suggestion of using syrup in the bottom tray to be useful. They are attracted not to sweet things per se (gnats, I mean- fruit flies are different), but to decay and fermentation. You'd be better served using milk or maybe fruit juice, or red wine or vinegar. Something which goes sour or ferments. Syrup doesn't do either, and I perceived no benefit from it.