The best cure for stray thoughts mentioned in the Hadith is for one not to pay any attention to them. This cure has proven to be extremely effective in repelling stray thoughts. Stray thoughts were something that even the Sahaabah (radhiyallahu ‘anhum) experienced. However, when they would mention their condition to Rasulullah (sallallahu ‘alaihi wasallam), he would advise them not to pay any attention to the stray thoughts that cross their minds. Therefore, one should neither pay any attention to these stray thoughts that cross the mind nor should he show any importance to them.
(Qutbul Aqtaab Hazrat Sheikhul Hadith Moulana Muhammad Zakariyya (rahmatullahi ‘alaih) pg. 424)