It is right to thank someone who benefits you even if he wished you badly. It is even more right to thank someone who benefits you but is indifferent to you. It is still more right to thank someone who deliberately benefits you out of regard for your welfare.