Converting a c# commandline app to a Windows service

后端 未结 3 543
逝去的感伤
逝去的感伤 2021-01-01 04:45

I found plenty of partial answers, but nothing really sufficient.

The case: App is a working command line app, with no user interaction, except for the ability to re

3条回答
  •  一向
    一向 (楼主)
    2021-01-01 05:38

    Best thing for you to do is to start a new Project as a windows service. In this new project you will find Service1.cs and this is the file that will be run from start. the following code will be int the file:

    namespace WindowsService1
    {
        public partial class Service1 : ServiceBase
        {
            public Service1()
            {
            InitializeComponent();
            }
    
            protected override void OnStart(string[] args)
            {
            }
    
            protected override void OnStop()
            {
            }
        }
    }
    

    It isnt that hard to figure out what to do from here. Simply add your classes to the project and make sure that you copy your main code in the the OnStart() function. Of course you might have to slightly edit the code to make sure it has no readlines in it.

    Now you must create and installer. How you can do this can be found here: http://msdn.microsoft.com/en-us/library/zt39148a%28v=vs.100%29.aspx

    I hope this helped :D

    Kind Regards

    RoXaS

提交回复
热议问题