First of all, we need to agree on the standards which rule our life and existence.
1. If you believe in Allah (SWT) then you should never think about killing or harming yourself no matter how much difficulties you feel that you have. You need to listen to Allah (SWT) and see that He is The Most Merciful. No problem can be bigger than His Mercy. His Mercy has included every thing. In Quran, Allah says (And My Mercy has included every thing) (7:156).
If you do not believe in Allah (SWT), God Forbid, you can not deny believing in Reason and intellect. You should never think about killing or harming yourself because because it goes against reason and intellect.
The way out of suicidal thoughts is to remember Allah (SWT) and His countless bounties if you are believer in Allah (SWT) or to remember your intellect and reason to see that suicidal thoughts are completely wrong and will never bring any relief of termination to your problems.
We are not allowed to kill or harm an animal, so, how can you think about killing or harming yourself?
Keep on repeating (YA ARHAM ARRAHIMEEN) (O THE MOST MERCIFUL).