Know in advance what the payoff is.
I find that if I know that the benefit far outweighs the difficulty, it's easier to stick to it.
The inverse also applies; If I determine that the payoff is low compared to the effort required, I drop it like a hot potato.