Blog Stats
  • Posts - 10
  • Articles - 0
  • Comments - 1
  • Trackbacks - 0

 

Debugging Window Service applications

Here is a neat and simple solution enabling you to develop, test and debug your Windows Service application before you deploy it.

  • When in DEBUG mode run a WinForm application with Start, Pause, Resume and Stop buttons
  • When in RELEASE mode run the code as you would your real service.

  • Begin by creating your Windows Service project in Visual Studio 2008.

    I decided that the best place to handle the mode detection would be in the program.cs file. Open it and modify it to look similar to the following, and hey presto - you have an easy to debug Windows Service:

    static void Main()
    {
    #if DEBUG
    	System.Windows.Forms.Application.Run(new frmHarness());
    #else
    	ServiceBase[] ServicesToRun;
    	ServicesToRun = new ServiceBase[] 
    	{ 
    		new Service() 
    	};
    	ServiceBase.Run(ServicesToRun);
    #endif
    }
    
    • Share This Post:
    • Share on Twitter
    • Share on Facebook
    • Share on Technorati

    Feedback

    No comments posted yet.


    Post A Comment
    Title:
    Name:
    Email:
    Website:
    Comment:
    Verification:
     
     

     

     

    Copyright © LEV