In a small pot, mix together about three quarter of the milk, half of the sugar, and the vanilla extract. Bring to a boil on medium heat.
In a bowl, mix together (with a whisk) the rest of the sugar with the cornstarch. Add the remaining of the milk and mix together again until smooth.
When the milk starts to boil, pour some of it in the bowl, mix well, and pour everything back into the pot.
Cook on medium heat (stirring continuously) until it boils, and cook for one more minute from that point on.
Remove the pot from the stove and stir in the margarine until fully incorporated.
Transfer the cream in a bowl, cover with plastic wrap directly on the surface of the cream. Allow to cool down at room temperature before storing in the fridge until set.