I use the following conditional pattern to debug a Windows Service in C#.
This has the advantage that if you run in debug mode in Visual Studio, the
service never needs to be installed - it is simply run as a "plain old"
executable. No need to attach anything, just set a breakpoint:
#if ( ! DEBUG )
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] {new TestService()};
ServiceBase.Run(ServicesToRun);
#else
// debug code: allows the process to run as a non-service
// will kick off the service start point, but never kill it
// shut down the debugger to exit
TestService service = new TestService();
service.OnStart(null);
Thread.Sleep(Timeout.Infinite);
#endif
--
Recursion: see Recursion
site:
http://www.eggheadcafe.com
unBlog:
http://petesbloggerama.blogspot.com
BlogMetaFinder:
http://www.blogmetafinder.com
"Martin Arvidsson, Visual Systems AB" wrote:
Hi!
To debug a service i usually attach to the service when it is running.
How ever in this case. the service is not starting due to an error when i
initialize the
service, therefor the service is not started and i can not debug it. (Step
thru code)
Can you "pre" attach to the service before the service is running?
Any other tips on how to debug?
I have began to remove code line by code line, but there is a lot of code :)
Regards
Martin