472,143 Members | 1,451 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

how to debug windows service

hi all,
how to debug windows service in c#.net

thanks in advance
Regards,
Tulasi


Dec 29 '05 #1
5 13234
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
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
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
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
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.

Similar topics

5 posts views Thread by SiD` | last post: by
4 posts views Thread by Rob R. Ainscough | last post: by
7 posts views Thread by Sunil Varma | last post: by
2 posts views Thread by Elioth | last post: by
1 post views Thread by thomas | last post: by
5 posts views Thread by Jeff | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.