Debugging a Windows Service

  • Thread starter Carlos Sosa Albert
  • Start date
C

Carlos Sosa Albert

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.
 
B

Bryan Phillips

I use this for everything:

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

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

Carlos Sosa Albert

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 said:
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



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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top