One development:
1. New Console Program
2, NuGet download topshelf, according to different NET version select Download version, i 4.5 download 3.3.1
3. Increase in Main method
Hostfactory.run (x ={X.service<Rabbit> (s ={s.constructusing (name=NewRabbit ());//rabbit is the following specific business class to achieve a specific business s.whenstarted (RA=RA. Start ());//start () Rabbit class method
s.whenstopped (RA=Ra. Stop ()); //stop () Rabbit class Method
}); //X.runaslocalsystem ();X.runaslocalsystem (); X.setdescription ("order complete upgrade to shop"); The contents of the description bar on the Service tab in Service Manager x.setdisplayname ("Ordercompleteupgradetoshop");//The Service tab name bar in Task Manager displays content X.setservicename ("Ordercompleteupgradetoshop");//Service Manager Display name x.startautomatically ();//Auto Start, startup mode });
Public class Rabbit { publicvoid Start () { // implementation } publicvoid Stop () { // implementation } }
Two Installation Services:
Installation RabbitWinServer.exe Install start RabbitWinServer.exe start stop RabbitWinServer.exe stop uninstall RabbitWinServer.exe Uninstall
After you build the project, you can find the generated file in the Debug folder, shift+ the right mouse button pops up "Open command Window Here" and run the corresponding code above
Note: Where RabbitWinServer.exe is the name of the EXE
Three-view service installation and Operation Results:
Complete
Related illustrations:
Topshelf Windows Services