|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Debug Windows ServicesElioth,
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(ServicesToRun) End If End Sub Brian Elioth wrote: Show quoteHide quote > Hi, > > How I Debug a Windows Services in VB 2005? > > Thanks for all help. > > Elioth A third option is to P/Invoke the DebugBreak method.
/claes Show quoteHide quote "Brian Gideon" <briangid***@yahoo.com> wrote in message news:1155305289.596195.35830@i42g2000cwa.googlegroups.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(ServicesToRun) > > End If > > End Sub > > Brian > > > Elioth wrote: >> Hi, >> >> How I Debug a Windows Services in VB 2005? >> >> Thanks for all help. >> >> Elioth > |
|||||||||||||||||||||||