Wednesday, March 07, 2007

Debugging .net windows service

Ever faced by the challenge of debugging windows service autmatically. These lines of code below in the main routine of your windows service will help you break in to the debug mode. This is pretty helpful when you want to debug and test your win service without actually deploying it on the box as well.

static void Main()
{
#if (!DEBUG)
ServiceBase.Run(new WindowsService());
#else
System.Diagnostics.Debugger.Break();
ServiceBase.Run(new WindowsService());
#endif
}

Check the MS site for step by step debugging win service... http://msdn2.microsoft.com/en-us/library/7a50syb3(VS.80).aspx

Credits - Swati for bringing this to my attention! :)
Thanks - Dipesh

No comments: