Topshelf Windows Services

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.