The main danger period is mid-May when the flies are most common. One simple solution is to postpone sowing maincrop varieties until June. In addition, pay special attention to firming back the soil after any thinning, and perform this task as late in the day as possible. The use of pelleted seed is another alternative - it will reduce the need for thinning.
Below is an extract from the GardenAction forum of a post by Mary. It sounds worthwhile trying!
"Hi all, just a little info. After reading all the advice I could find on carrots and onions, I had a plan of attack!! I planted alternate rows of carrot seeds and onion sets, leaving about 15 inches for weeding and walking between them. Once the carrots were about 2-3 inches high, I earthed both them and the onions up as I had read this can help prevent carrot and onion fly, as should the alternate rows planting thingy. I didn't touch them, not even to thin the carrots!! until they were ready for young carrots to be picked, and used this as my 'thinning' technique. I am pleased to report I have had not one single carrot or onion fly, and although the carrots are seriously overcrowded, they are delicious, and only a few are twisted together. I am now picking them every 2 days or so for the kitchen, thinning as I go, and they are now 4-5 inches long, straight, and up to 1 inch across. I will most definitely earth them up in future, and not touch during carrot fly month. I hope this info. will be useful to anyone with carrot fly problems. Also last year, I had ants farming things in the top of my carrots, not so this year with the earthing up. Good luck everyone , Mary"