Starting/debugging a Windows Service inside Visual Studio 2008?

curiouswebster
curiouswebster used Ask the Experts™
on
I am about to write my first Windows Service.  But heard you cannot start or debug a Windows Service inside Visual Studio 2008?

Is that true?

If so, how am I supposed to make it work?  Do I need to resort to using the log file?

Any other ideas?

Thanks,
newbieweb
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior consultant
Commented:
We have a service and basically we created a console project that is a windows service in order to debug we don't have an issue but for release mode we simply set the conditional compilations symbols under the build option on the project properties to SERVICE otherwise under debug we leave it empty and it works fine
hope this helps you
curiouswebsterSoftware Engineer

Author

Commented:
Maybe that explains why my architect, who said Windows Services can not be debugged, made a console application to demostrate communications with Remoting.

How do I check if the console aplicationcan be converted to a Windows Service?  That's a very interesting trasformation...

Thanks,
newbieweb

Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Commented:
You can attach the debugger to a running service.  I just get in the habit of having the OnStart event just start a 30 second timer, and then the timer elapsed event does the actual initialization.  This gives me enough time to attach the debugger.
curiouswebsterSoftware Engineer

Author

Commented:
I'm again talked to my architect who says to develop this as a console app, for debug purposes, then as the final act convert to a Windows Service.  So just like you said.

Could you give me more specifics on how to make that conversion?

Thanks a lot,
newbieweb
Grant SpiteriSenior consultant
Commented:
1. Extend System.ServiceProcess.ServiceBase for Runtime
2. Implement System.Configuration.Install.Installer for Installer
Carl TawnSenior Systems and Integration Developer
Commented:
The easiest way to do what you want is to code all of the logic for your service in to a seperate code library. Your service then essentially only acts as an entry point, rather than having the full application code written into the service itself.

Moving your code into a seperate library means you can easily test it from a console app (or even using TDD if you're that way inclined), and then wrap a Windows Service around it when you are done.
curiouswebsterSoftware Engineer

Author

Commented:
Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial