VISUAL STUDIO C# RUN WINDOWS SERVICE WITHOUT INSTALL

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace BMSPDAWINDOWS_SERVICE {
    static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main() {
#if (!DEBUG)
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new Service1()
            };
            ServiceBase.Run(ServicesToRun);
#else
            Service1 myServ = new Service1();
            myServ.START_PROCESS(true);
            // here Process is my Service function
            // that will run when my service onstart is call
            // you need to call your own method or function name here instead of Process();
#endif
        }
    }
}

PROGRAM.CS SHOULD LIKE ABOVE

NOTE: IN SERVICE1.CS SHOULD MADE START_PROCESS PUBLIC

Leave a comment