If you tell yourself not to think of something, the reverse will happen. Tell yourself not to think of pink elephants and that's all you'll think about.
It's also important to note that thoughts don't equate fact. If I think, for instance, that I am an international superstar, no matter how often or how hard I think it, it's not reality. The same works for obsessive thoughts. Say my current obsession is I fear I might harm someone. (
This is a very common OCD thought). The thought itself does not cause harm to come to anyone. I can think it, but thinking isn't action. In particular, if you respond to these thoughts with revulsion rather than pleasure, you can pretty much identify they aren't homicidal thoughts.
OCD is an anxiety disorder, therefore the thoughts generated reflect things you fear. If you fear something, you're not going to do it intentionally...the same way I fear spiders, so it's doubtful I'd buy a pet tarantula. Therefore, the key to minimizing the anxiety associated with these thoughts is simply to not respond to them. Don't fight them, don't talk to them, don't bargain with them --
just let them be there. They aren't hurting you. Things that aren't real can't cause harm in this capacity; if you know the thought isn't real or irrational (as most people with OCD do), then its existence doesn't threaten you. Heck, rather than fight the thought, try encouraging it. Be as obsessive about that thought as possible, and do so willingly. Make the thought boring rather than frightening, and you will find yourself thinking about it less and less.