Yeah, I agree with Ant.
I don't know there is necessarily a way of stopping these episodes from happening, but by recognising them for what they are and not trying to suppress or ignore them, or feel as though you're stupid for feeling how you are (difficult, I know) is a pretty big step forward.
The hardest part I've found over the past five years or so, is having to accept that feeling shit a lot of the time is just something I have to deal with and mitigate as best I can. It's not easy, it's a daily struggle and at times can become overwhelming. Being able to move on is something I really struggle with - it fucks me off no end when people say I've got to leave things in the past and move on. I know that, and if it was just as simple as putting those words into practice, I'd have started doing it 20 years ago. There's isn't a silver bullet that just makes everything okay all of a sudden, sadly.
My own way of dealing with it is simply by cutting myself off and withdrawing from most other people until I feel I'm in a better headspace - probably not the healthiest way of dealing with it, but it works best for me.
So, probably scant consolation @meowington - really sorry that you're feeling so low. If there is any consolation in knowing that others can understand how you're feeling, then I hope it helps.
Take care x