Geeks With Blogs
Michael Holland
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
    }
    
    Posted on Thursday, February 5, 2009 4:56 PM | Back to top


    Comments on this post: Debugging Window Service applications

    No comments posted yet.
    Your comment:
     (will show your gravatar)


    Copyright © LEV | Powered by: GeeksWithBlogs.net