First, the official website and source code download1, the official website: http://topshelf-project.com/2, source download: https://github.com/Topshelf/Topshelf/downloads
Ii. Creating a service using Topshelf
1 Static voidMain (string[] args)2 {3Hostfactory.run (x =4 {5X.service<myservice> (Dtservice =6 {7serviceconfigurator<myservice> DtS = Dtservice asServiceconfigurator<myservice>;8Dts.constructusing (name =NewMyService ());9dts.whenstarted (TC =TC. Start ());Tendts.whenstopped (TC =TC. Stop ()); One }); AX.runaslocalsystem ();//you need to start the service with "Local System" privileges, or it will be reported that HTTP could not be registered - x.startautomatically (); -X.setservicename ("your own cloud service"); theX.setdisplayname ("your own cloud service"); -X.setdescription ("your own cloud service"); - }); -}
classMyService {Private voidProcess (Objectsender, Elapsedeventargs Arg) { } /// <summary> ///Start the service/// </summary> Public voidStart () { }/// <summary> ///Stop Service/// </summary> Public voidStop () {}}
Third, the installation of services
1.CD to. exe directories
2.your.exe Install//installation
3.your.exe Start//Startup
Such a simple Windows service is OK.
How to use Topshelf to manage Windows services