What sort of thoughts are going through your head right before this thought appears? I often have thoughts like this when I am anxious or feeling angry at myself, except that I imagine stabbing myself in the leg or arm. My therapist said that it is my mind's response to stress, like when some people self-harm, except that I have not gotten upset enough yet to do actual harm to myself.
If you can figure out what is triggering these thoughts, then you can try to counteract then by dealing with the stress in a better way, through relaxation exercises or positive self-talk.
I hope this gets better for you. I know how it feels to be so stressed out and not know how to stop it.
_________________
Your Aspie score: 120 of 200 ; Your neurotypical (non-autistic) score: 90 of 200
You seem to have both Aspie and neurotypical traits
Self-DX: Extreme Introvert, possibly with ADHD-Primarily Inattentive; Official DX: Generalized Anxiety Disorder