Hi guys,

I'm trying to do just this, debug a Windows Service. I tried some ways I
found around the net but I wasn't able to get it to work.

This I found at http://www.codeproject.com/dotnet/DebugWinServices.asp and
seems like a nice approach, but when it talks about "<Your Service's Primary
Method Here>" I don't know what to do... =/

Any help, will gonna be VERY welcome.

//#if (!DEBUG)
// System.ServiceProcess.ServiceBase[] ServicesToRun;
// ServicesToRun = new ServiceBase[] { new Service1() };
// ServiceBase.Run(ServicesToRun);
//#else
// // Debug code: this allows the process to run as a
non-service.
// // It will kick off the service start point, but never
kill it.
// // Shut down the debugger to exit
// Service1 service = new Service1();
// service.<Your Service's Primary Method Here>();
// // Put a breakpoint on the following line to always catch
// // your service when it has finished its work
//
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
//#endif

Thanks,

Charly.

Re: Debugging a Windows Service by Bryan

Bryan
Tue Jun 05 20:46:36 CDT 2007

I use this for everything:

#if DEBUG
if (!System.Diagnostics.Debugger.IsAttached){
System.Diagnostics.Debugger.Launch();
}

System.Diagnostics.Debugger.Break();
#endif

--
Bryan Phillips
MCT, MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com
Web Site: http://www.composablesystems.net



"Carlos Sosa Albert" <betun (at) hotmail> wrote in message
news:uOZWAO7pHHA.588@TK2MSFTNGP06.phx.gbl:

> Hi guys,
>
> I'm trying to do just this, debug a Windows Service. I tried some ways I
> found around the net but I wasn't able to get it to work.
>
> This I found at http://www.codeproject.com/dotnet/DebugWinServices.asp and
> seems like a nice approach, but when it talks about "<Your Service's Primary
> Method Here>" I don't know what to do... =/
>
> Any help, will gonna be VERY welcome.
>
> //#if (!DEBUG)
> // System.ServiceProcess.ServiceBase[] ServicesToRun;
> // ServicesToRun = new ServiceBase[] { new Service1() };
> // ServiceBase.Run(ServicesToRun);
> //#else
> // // Debug code: this allows the process to run as a
> non-service.
> // // It will kick off the service start point, but never
> kill it.
> // // Shut down the debugger to exit
> // Service1 service = new Service1();
> // service.<Your Service's Primary Method Here>();
> // // Put a breakpoint on the following line to always catch
> // // your service when it has finished its work
> //
> System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
> //#endif
>
> Thanks,
>
> Charly.


Re: Debugging a Windows Service by Carlos

Carlos
Wed Jun 06 08:10:25 CDT 2007

Thanks a lot Bryan, it worked like a charm.

Do you by any chance have some link/idea of documentation about Windows
services? Is the first one I'm working on and I feel a little bit lost... =P

"Bryan Phillips" <bphillips@nospam.spamcop.net.spammenot> wrote in message
news:#H3$Hy9pHHA.3512@TK2MSFTNGP06.phx.gbl...
>I use this for everything:
>
> #if DEBUG
> if (!System.Diagnostics.Debugger.IsAttached){
> System.Diagnostics.Debugger.Launch();
> }
>
> System.Diagnostics.Debugger.Break();
> #endif
>
> --
> Bryan Phillips
> MCT, MCSD, MCDBA, MCSE
> Blog: http://bphillips76.spaces.live.com
> Web Site: http://www.composablesystems.net
>
>
>
> "Carlos Sosa Albert" <betun (at) hotmail> wrote in message
> news:uOZWAO7pHHA.588@TK2MSFTNGP06.phx.gbl:
>
>> Hi guys,
>>
>> I'm trying to do just this, debug a Windows Service. I tried some ways I
>> found around the net but I wasn't able to get it to work.
>>
>> This I found at http://www.codeproject.com/dotnet/DebugWinServices.asp
>> and
>> seems like a nice approach, but when it talks about "<Your Service's
>> Primary
>> Method Here>" I don't know what to do... =/
>>
>> Any help, will gonna be VERY welcome.
>>
>> //#if (!DEBUG)
>> // System.ServiceProcess.ServiceBase[] ServicesToRun;
>> // ServicesToRun = new ServiceBase[] { new Service1() };
>> // ServiceBase.Run(ServicesToRun);
>> //#else
>> // // Debug code: this allows the process to run as a
>> non-service.
>> // // It will kick off the service start point, but never
>> kill it.
>> // // Shut down the debugger to exit
>> // Service1 service = new Service1();
>> // service.<Your Service's Primary Method Here>();
>> // // Put a breakpoint on the following line to always
>> catch
>> // // your service when it has finished its work
>> //
>> System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
>> //#endif
>>
>> Thanks,
>>
>> Charly.
>