Running Windows Service Application without installing it

后端 未结 6 1869
旧巷少年郎
旧巷少年郎 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:43

    You cannot run Windows Service as say another console or WinForms application. It needs to be started by Windows itself.

    If you don't have infrastructure ready to use as @Damien_The_Unbeliever suggests (which is what I recommend as well) you can install the service from the debug location. So you use installutil once and point it to executable located in /bin/debug. Then you start a service from services.msc and use Visual Studio > Debug > Attach to Process menu and attach to the Windows service.

    You can also consider using Thread.Sleep(10000) as the first line in the OnStart call, or Debugger.Break() to help you out to be able to attach before the service executes any work. Don't forget to remove those before the release.

提交回复
热议问题