Showing posts with label debug. Show all posts
Showing posts with label debug. Show all posts

Sunday, September 24, 2017

Debug Windows Services

Out of the box, one cannot debug a Windows Service easily through Visual Studio.

Making this possible via code is very easy though.

One just needs to change the code in Program.cs to

#if DEBUG
           Service1 debugInstance = new Service1();
           debugInstance.OnDebug();

           Thread.Sleep(Timeout.Infinite);
#else
           ServiceBase[] ServicesToRun;
           ServicesToRun = new ServiceBase[]
           {
               new Service1()
           };
           ServiceBase.Run(ServicesToRun);
#endif


And add an OnDebug method to the partial class that implements ServiceBase, and has the OnStart() and OnStop() methods.

  public void OnDebug()
        {
        }


This will now be your entry point into debugging your Windows Service through Visual Studio.

Monday, August 20, 2012

Reasons to remove debug=true from web.config

Before deploying your web application, always ensure that debug=true is removed. These are some side effects of leaving this in, which might be useful while debugging, but which be a huge cost once you go live.


  • Files needed for your application are not created immediately.
  • Temporary files are created
  • There is no timeout in debugging
  • Batch compilation is disabled
  • System.Diagnostics.DebuggableAttribute gets added to all generated code which causes performance degradation.
  • Scripts and images are not cached