By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,908 Members | 2,055 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,908 IT Pros & Developers. It's quick & easy.

how to debug windows service

P: n/a
hi all,
how to debug windows service in c#.net

thanks in advance
Regards,
Tulasi


Dec 29 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
There are 2 main ways to do this. I prefer to build business classes that do
the actual work of the service. I can then test them in a Windows
executable, and once debugged, plug them into a service. The other way is a
bit more difficult.

You create your Service. You install it and start it. In Visual Studio.Net,
you attach to the process (Debug|Processes... menu), and then you can debug
as usual.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"TulasiKumar" <tu*********@nannacomputers.com> wrote in message
news:e3***************@TK2MSFTNGP15.phx.gbl...
hi all,
how to debug windows service in c#.net

thanks in advance
Regards,
Tulasi

Dec 29 '05 #2

P: n/a
Hi,
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
You create your Service. You install it and start it. In Visual
Studio.Net, you attach to the process (Debug|Processes... menu), and then
you can debug as usual.


Note that in this way you cannot debug the onStart event.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Dec 29 '05 #3

P: n/a
True. Another reason why I use business classes instead!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:u%*****************@tk2msftngp13.phx.gbl...
Hi,
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
You create your Service. You install it and start it. In Visual
Studio.Net, you attach to the process (Debug|Processes... menu), and then
you can debug as usual.


Note that in this way you cannot debug the onStart event.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Dec 29 '05 #4

P: n/a
Try something like this:

#if ( ! DEBUG )
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] {new YourService()};
ServiceBase.Run(ServicesToRun);
Run();
#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
YourService service = new YourService();
service.OnStart(null);
Thread.Sleep(Timeout.Infinite);
#endif

-- Peter
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"TulasiKumar" wrote:
hi all,
how to debug windows service in c#.net

thanks in advance
Regards,
Tulasi


Dec 29 '05 #5

P: n/a
Hi,

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:uR**************@TK2MSFTNGP14.phx.gbl...
True. Another reason why I use business classes instead!


Yes, but beware, a windows service's environment is very different than a
win. based app. , the permissions changes , like you cannot access a network
shared, or the mapped drivers are not presents.

Also a difference is that a service needs to be installed, it cannot be run
as simple as pressing F5 , if you change the code you have to stop the
service, recompile it, copy the executable to the installed folder and
restart the service.


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Dec 29 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.