These are called intrusive thoughts. I have learned about these through a family member with ADHD. With ADHD, you can have the dual problem of both the wandering, intrusive thoughts, with sometimes the lack of impulse control. It can be really dangerous for some.
What the poster is talking about is different, something that occurs in a deep depression where your mind is struggling to find a way out of the situation. Sometimes the will gives out completely and you're just a zombie to the world, only slogging forward out of habit and maybe guilt.