Probably a problem with permissions. As the commentator said, try running VStudio or your compiled service as an administrator.
In addition, you can still debug the service - put thread.Sleep (up to 20 seconds) as the first line (to give time for the debugger to attach), and then put a breakpoint on the line. Then go to Tools -> Attach To Process and select your .exe. If you do this to the end of your Thread.Sleep (), you must break.
Keep in mind that the service must complete OnStart during the second stage of IIRC, or Windows will think that it does not respond and does not kill your process, so move the code from the service start if you are going to debug a lot. Just drop the timer there or something else.
To simplify debugging, think about porting your functionality to a DLL, and then save your service with enough code to call into your DLL - this will facilitate unit testing and debugging - but don't forget that a lot changes when you actually run it as a service.
source share