This source code was got from dotnet-tricks.com