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

Debug Windows Services

P: n/a
Hi,

How I Debug a Windows Services in VB 2005?

Thanks for all help.

Elioth
Aug 10 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Elioth,

You have a couple of options.

1) Start the service in the Service Control Manager and attach the VS
debugger to a running process via Debug | Processes. I don't like this
option because the application may have already performed a lot of work
before you can attach and set a breakpoint.

2) Setup the application to run either as a service or a console
application. It's much easier to debug a console application. The
following code demonstrates what I'm talking about. There are several
variations on this theme including the use of conditional compilation.

Shared Sub Main()

If Environment.UserInteractive Then

' Run as a console application.
Dim service As Service1 = New Service1
service.OnStart(Nothing)
Console.WriteLine("Press ENTER to quit...")
Console.ReadLine()
service.OnStop()

Else

' Assume the Service Control Manager invoked the application.
Dim ServicesToRun() As ServiceBase
ServicesToRun = New ServiceBase () {New Service1}
System.ServiceProcess.ServiceBase.Run(ServicesToRu n)

End If

End Sub

Brian
Elioth wrote:
Hi,

How I Debug a Windows Services in VB 2005?

Thanks for all help.

Elioth
Aug 11 '06 #2

P: n/a
A third option is to P/Invoke the DebugBreak method.

/claes

"Brian Gideon" <br*********@yahoo.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Elioth,

You have a couple of options.

1) Start the service in the Service Control Manager and attach the VS
debugger to a running process via Debug | Processes. I don't like this
option because the application may have already performed a lot of work
before you can attach and set a breakpoint.

2) Setup the application to run either as a service or a console
application. It's much easier to debug a console application. The
following code demonstrates what I'm talking about. There are several
variations on this theme including the use of conditional compilation.

Shared Sub Main()

If Environment.UserInteractive Then

' Run as a console application.
Dim service As Service1 = New Service1
service.OnStart(Nothing)
Console.WriteLine("Press ENTER to quit...")
Console.ReadLine()
service.OnStop()

Else

' Assume the Service Control Manager invoked the application.
Dim ServicesToRun() As ServiceBase
ServicesToRun = New ServiceBase () {New Service1}
System.ServiceProcess.ServiceBase.Run(ServicesToRu n)

End If

End Sub

Brian
Elioth wrote:
>Hi,

How I Debug a Windows Services in VB 2005?

Thanks for all help.

Elioth

Aug 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.