RE: Could not Debug

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi Siva,

Thanks for your post!

Yes, Windows Service is a special type of application in Windows world, it
is different from GUI or console Applications. Below is some difference
details:
1. Windows Service is communicating with SCM, and it must obey the rule of
SCM. For example, while the service is starting, SCM allows the service to
response in 30 seconds, if the service does not response in this period,
SCM will kill your service. So was the stop or any other actions.
2. Windows Service normally runs in another Logon Session, so it has its
own Windows Station/Desktop, which is different from our interactive
Windows Station/Desktop. So its output will be invisible to us.(For
example, if you use Process.Start to lauch a notepad, you will find you can
not see it)

Because of these features, Windows Services become the hardest type of
application to debug except Windows Driver.

Based on the above background information, normally, the easiest way to
debug windows service application is first run it normally as a console
application, after performing the normal code stepping and debugging, you
may release and install it. This is easy to be done, the article below
shows this trick:
"Debugging Windows Services under Visual Studio .NET"
http://www.codeproject.com/dotnet/DebugWinServices.asp

However, this trick can only to test half of your code, because your code
may run well under console application, but it fails while running as a
service.(Normally, because of #1 and #2 features). At runtime, after your
service is started, you may use VS.net to attach to the service running
process and perform the debugging. Genernal information can be found in the
article below:
"How to: Debug Windows Service Applications"
http://msdn2.microsoft.com/en-us/library/7a50syb3.aspx

Finally, if you want to log information from Windows Service, because of
#2, we can not simply output it with Console.WriteLine. The easiest way is
using EventLog, please refer to:
"How to: Log Information About Services"
http://msdn2.microsoft.com/en-us/library/f6567h1s.aspx

Above is the general debugging guideline, if you still have some specific
difficulties, please feel free to tell me. Thanks!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

.



Relevant Pages

  • Re: Background C# Service
    ... A Windows Service is just a type of Visual Studio project like Windows Forms ... or Console Application. ... simpler to leave it as a console app and just use Windows Scheduler to fire ... > result set in a specific format. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: App hung using COM behind the scenes
    ... I am in development right now, so VS is set to run the console app which is ... keypress to exit because if that thread does return the application exits. ... there is no Mainin the service project to put the ... You may try to create a simple windows service project and you will see the ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Start and impersonate a console app from windows service
    ... I have just tried changing the LogonFlag of the CreateProcessWithLogonW ... So windows service has no problem starting a new process. ... The application I want to start is a console app and it also opens a win ... If I start this application without the impersonate, ...
    (microsoft.public.dotnet.framework)
  • Re: Self terminating windows service
    ... Nicholas Paldino ... I am using this windows service to ... > applications and at that time I want to check the performance counters. ... > the service with out using console applpication. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Windows service with console
    ... It could be a security issue, but wouldn't be in this instance, basically we ... we need to be able to have some sort of console output, ... >> I'd like to write a windows service in .net, in itself that's not a big ... >> write a trace listener to listen for information from the service? ...
    (microsoft.public.dotnet.framework)