The rapid growth of a stem as it begins to flower is a process known as bolting. It's a process that can be considered both good and bad, depending on the plant in question.
In the case of many perennials, for example, bolting is exactly what you want to happen. Otherwise, the showy flowers would never appear, and there would be nothing but foliage to enjoy. However, in the case of some other plants, especially edible plants, bolting is a bad thing.
Cilantro is an herb that's one of the most prone to bolting, and although you may try, it's difficult to prevent cilantro from bolting within a few weeks after planting. The problem with bolting is that once it begins, the foliage loses much of its flavor. Yet, in the case of cilantro, the flower ultimately yields a seed known as coriander.
A number of veggies will bolt in response to higher temperatures and changes in daylength. For example, when the leaves of spinach begin to develop pointy ends, that's a sure sign it's beginning to bolt. You can arrest the process temporarily by simply cutting the elongated stem as it begins to form. But you're fighting a losing battle, so ultimately your best bet is to simply harvest what you can and remove the plant, making room for another crop.