RE: How to Debug a Windows Service
- From: Bruno van Dooren <bruno_nos_pam_van_dooren@xxxxxxxxxxx>
- Date: Tue, 11 Apr 2006 03:52:01 -0700
Did you write a service using .NET or win32?
I have always used win32. search www.codeproject.com for .NET examples.
I wrote a Windows Service in VC.NET 2005
I want to debug the solution.
I tried as mentioned in the following link.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconintroductiontontserviceapplications.asp
But, when I started the service I got a message box saying that the
service is being stopped.
The page you mention contains a link to 'debugging windows services' which
contains this explanation:
<snip>
Attaching to the service's process allows you to debug most but not all of
the service's code; for example, because the service has already been
started, you cannot debug the code in the service's OnStart method this way,
or the code in the Main method that is used to load the service.
</snip>
If all your code is in OnStart, you cannot debug it according to this.
What you could do is to is to print logging information to a text file
though that should at least give you some idea of what is happening inside
OnStart
And also I would like to know whether the application code is to be
written in the OnStart() method or not.
You can do it, but it is not mandatory. I have done it like that a couple of
times, but you don't have to. at least in win32 services.
One more problem that i faced while executing the Windows Service is,
if i try to pop-up a message box, i get "Stopping the Service" message
when i start the Service.
Is your service allowed to interact with the user interface? Otherwise you
will never see the dialog box. You should never put UI features in a service
anyway because it can easily lead to security problems. And even if you
provide UI features, they will be invisible if noone is logged in.
What I do when i need to debug service functionality is that I launch it in
the IDE, but with an argument that specifies it is running as a console
application instead of a service. that will instruct the application to
directly go to the function where the functionality of the program starts so
that the service stuff is skipped.
That ways you can debug all your code in the VS IDE. then , when you know it
works, you can start is as a service.
The platform SDK contains an example that does that exact same thing, but i
don't know if it is easy to do the same if you are using .NET to program a
service.
--
Kind regards,
Bruno.
bruno_nos_pam_van_dooren@xxxxxxxxxxx
Remove only "_nos_pam"
.
- Follow-Ups:
- Re: How to Debug a Windows Service
- From: Sunil Varma
- Re: How to Debug a Windows Service
- References:
- How to Debug a Windows Service
- From: Sunil Varma
- How to Debug a Windows Service
- Prev by Date: How to Debug a Windows Service
- Next by Date: Re: How to Debug a Windows Service
- Previous by thread: How to Debug a Windows Service
- Next by thread: Re: How to Debug a Windows Service
- Index(es):
Relevant Pages
|