Hazrat Moulana Ashraf Ali Thanwi (rahmatullahi ‘alaih) once mentioned:
The way to repel stray thoughts and the whispers of Shaitaan is to deal with them with courage and determination. Dealing with them with courage and determination is to totally ignore them and not pay any attention to them. This is similar to a stray barking dog. If you interfere with it and try to silence it, it will continue barking at you. However, if you ignore it, it will automatically stop barking. Hence the best way to deal with stray thoughts and the whispers of Shaitaan is for you to totally ignore them and not pay any attention to them. (Malfoozaat Hakeemul Ummat 7/210)