How do heartworms reproduce?

In graduate school I conducted research on heartworm disease and as a veterinarian I deal with it frequently, so I can provide a detailed response to this question.

There are both male and female heartworms (Dirofilaria immitis) which live in the heart and pulmonary vessels. The adult heartworms mate and, unlike many other parasites, which produce eggs, heartworms produce live offspring called microfilariae (singular form microfilaria). The microfilariae are NOT infective rather they have to undergo an obligatory developmental phase in a mosquito.

When a mosquito takes a blood meal from a heartworm-infected dog, it will draw in some microfilariae from the bloodstream. The microfilariae undergo changes in form inside the mosquito until it becomes an L3 (third stage larval form), which is the infective form. This typically takes 14 days or longer. When the mosquito takes another blood meal and injects the L3 heartworms into the skin of a dog (or cat). In 3-4 days, while in the skin, the larvae undergo another change in form to become an L4. Over the ensuing 2-3 months, they migrate to the heart/pulmonary vessels and gradually develop into the adult form. Approximately 6-7 months following the initial infection (when the L3s were injected into the skin) the adult worms are mature, begin mating and produce microfilariae.