For me, it was figuring out where those thoughts originated and why I felt offing myself was the answer.
When I realized it had to do with all the negative messaging from my abusive family of origin, I decided it was not the answer. They'd already done enough damage and I'd be damned if I gave them that (my life).
I've been in therapy for 30 years now, and still wrestle with those thoughts from time to time.
When they get too intense I ask my therapist to help me through it.