Running Windows Service Application without installing it

后端 未结 6 1873
旧巷少年郎
旧巷少年郎 2021-01-11 16:55

Whem I\'m writing a Windows Service and just hit F5 I get the error message that I have to install it using installutil.exe and then run it. In practice this me

6条回答
  •  北恋
    北恋 (楼主)
    2021-01-11 17:26

    The best way in my opinion is to use Debug directive. Below is an example for the same.

    #if(!DEBUG)
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] 
        { 
             // Calling MyService Constructor 
                new MyService() 
        };
         ServiceBase.Run(ServicesToRun);
    #else
      MyService serviceCall = new MyService();
      serviceCall.YourMethodContainingLogic();
    #endif
    

    Hit F5 And set a Breakpoint on your YourMethodContainingLogic Method to debug it.

提交回复
热议问题