Before a big event you have to have a good conversation with yourself and ask yourself, What am I prepared to go through? How much am I prepared to endure and suffer to achieve what I set out to? How much does it mean to me? What are my motivators? Who am I doing it for?
You have to know the answers inside out so that when the pain sets in, extreme fatigue leadens your limbs and your willpower flags, you have the answers for the devil who will sit on your shoulder and ask you over and over (figuratively speaking) why the hell are you doing this? Why don't you just stop.
There often comes a time in a race where you just negotiating with yourself and bargaining and you have to know that in advance and cut that thinking off at the pass.
You cant say, for e.g. ... well this is the longest I have ever run at least, and I am happy with that so even if i don't finish thats not too bad. Those sort of internal conversations are deadly to your will power and your focus and give you an excuse to quit and that can be extremely painful afterwards when he pain subsides and you have given in and you cant go back. The pain of not finishing what you started can be worse than the pain of the race continuing.
Dont concentrate during the race on the whole distance, break it into manageable bites and the harder it gets the smaller those bites and repeat to yourself "This too will pass" no matter how slow time seems to tick over.
Don't waste time ever... i.e. if you stop you must have a damn good reason. There are times when you should rest, or stop but keep the pressure on yourself to get out again. Control points or check points can be lethal mentally. There is a saying "beware the chair" meaning the chair will entice you and if you let go in your mind for too long you won't get back out there.
Take breaks when you are in dire straits during an ultra if you need to rebalance your blood sugars or blood pressure or you are experiencing extreme dehydration or digestion upsets, these things don't necessarily mean the end of your race, take time if you can (and the cut offs are looming) rebalance yourself and keep going slowly. Dozens of times I have had to stop, throw up or lie down for a bit, calm my digestion etc but have fought on and completed the event. "It aint over till its over"