The present invention relates to a method of controlling a dispenser for dosing a product in a washing machine leading to an optimized dosing result, a dispenser controller programmed with an algorithm to execute the method of the present invention as well as to the use of said dispenser for controlling dosing of a product in a washing machine.