Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to debug Windows Service Applications in C#

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 802
    Comment on it

    When we creating a windows service, we need to test it before installing.Window service is not directly run through Visual Studio.There are many other method to debug the window service. I explained here one of the method to debug the window service.

    This is the easier way for testing or debugging windows services by changing the code only in Program.cs file.

    Here, below is the code:

    static class Program
    {
    	/// <summary>
    	/// The main entry point for the application.
    	/// </summary>
    	static void Main()
    	{
    		ServiceBase[] ServicesToRun;
    		ServicesToRun = new ServiceBase[] 
    		{ 
    			new ServiceClassName()        // ServiceClassName where OnStart and OnStop method defined
    		};
    		ServiceBase.Run(ServicesToRun);
    		#if (!DEBUG)
    					ServiceBase[] ServicesToRun;
    					ServicesToRun = new ServiceBase[] 
    					{ 
    						new ServiceName() 
    					};
    					ServiceBase.Run(ServicesToRun);
    		#else
    					ClassName obj = new ClassName();
    					obj.MethodName();           //MethodName that you want to call for debugging
    		#endif
    	}
    }

    Hope this code will help you. Thanks

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: