I just had the same problem.
It turned out it was because I was running it as a console in debug mode – like the code you have above
#if (!DEBUG)
#else //debug code
#endif
And I had compiled it in debug mode and installed the service
When I compiled it in release mode it worked as expected
Hope this helps