First, the official website and source code download1, the official website: http://topshelf-project.com/2, source download: https://github.com/Topshelf/Topshelf/downloads
Second, topshelf Advantage1. CommissioningConvenient: You can create a console program without creating a Windows Service project, and start the console to debug your service code2. Install/Uninstall Service method
1, CMD-->CD program directory (directly to the directory where EXE files) 2, Installation Services: JwifiRoute.Message.LogServices.exe Install
3. Start the service:JwifiRoute.Message.LogServices.exe Start4.Uninstall service (need to perform multiple times to uninstall Service): JwifiRoute.Message.LogServices.exe Uninstall
Iii. Creating a service using topshelf
1. IntroductionTopshelf.dll 2, start the service
/// <summary> ///The main entry point for the application. /// </summary> Static voidMain () {Hostfactory.run (c={c.setservicename ("logservices"); C.setdisplayname ("logservices"); C.setdescription ("logservices"); C.service<TopshelfService> (s ={s.constructusing (b=NewTopshelfservice ()); S.whenstarted (o=O.start ()); s.whenstopped (o=o.stop ()); }); });
3. Service Program Logic
Public class Topshelfservice { publicvoid Start () { // service logic publicvoid Stop () { }}
Using Topshelf to manage Windows services