Converting a Console Application to a service?

前端 未结 5 931
[愿得一人]
[愿得一人] 2021-02-06 05:53

I\'m looking for different ways with strengths/weaknesses for converting a console application we are using long term in to a windows service. We use something called java serv

5条回答
  •  伪装坚强ぢ
    2021-02-06 06:51

    I would be tempted to create an empty windows service project, and just grab the bits that deal with a service; it isn't a lot - a few references and some of the code in Main. You can actually have your existing console work both as a service and as a console - either by checking the args to Main and using (for example) a "-console" switch, or I believe you can check Environment.UserInteractive.

    If it is in "console" mode, run your code as you do now; if it is in service mode, run the code you grabbed from the template project.

    For info, you can also have the same exe work as the installer/uninstaller for the service! I do this with "-install" / "-uninstall" switches. For an example, see here.

提交回复
热议问题