(Normally a restart isn't required for changes to the local HOSTS file to take effect.)
Your blocking technique may work better if you include both hostnames (and you can place more than one on a single line, or make several entries for the same IP address across multiple lines), one with the "www." prefix and one without (just as I'm showing here, except that I'm using "example.com" instead):
127.0.0.1 example.com www.example.com
The reason that blocking doesn't work as you expected is that the HOSTS file is very literal in the way it handles things, and you're probably using the "www." prefix variation of the hostname which I'm also assuming that you didn't define [since your example shows only one hostname without the "www." prefix].
If you were using a DNS server instead, then you could set up a zone for "example.com" and "www.example.com" would be included automatically (this is due to the hierarchial nature of DNS). The HOSTS file, on the other hand, will allow you to override IP addresses only for the hostnames you specify therein.
When resolving a hostname to an IP address, your computer normally consults the local HOSTS file first, followed by any local cache, and then queries DNS after that. This is done to preserve bandwidth, and it's very effective.
For a handful of computers, the local HOSTS file can be easy to manage, but for a large number of computers it's usually easier to set up a DNS server (with the zones you want to block added to resolve to nothing, or 127.0.0.1, or even an intranet server) and configure all the computers to use it.