Have a look at this MSDN article by James McCaffrey, I've been using a modified version of it for a while and it gave me very satisfying results. The article is very clear and the code is very clean and efficient.