Create a Windows service using Topshelf

Source: Internet
Author: User

1.Topshelf is another way to create a Windows service, Topshelf is an open-source, cross-platform hosting service framework that supports Windows and mono and can build a convenient service host with just a few lines of code.

2. Add Reference: Topshelf.dll

Topshelf.Log4Net.dll

3. Latest Version: Https://github.com/Topshelf/Topshelf/downloads

4. Official Case:

classProgram { Public Static voidMain () {Hostfactory.run (x=//1{X.service<TownCrier> (s =//2{s.constructusing (name=NewTowncrier ());//3s.whenstarted (TC = TC). Start ());//4s.whenstopped (TC = TC). Stop ());//5                });                            X.runaslocalsystem (); //6X.setdescription ("Sample topshelf Host");//7X.setdisplayname ("Stuff");//8X.setservicename ("Stuff");//9});//Ten        }    }     Public classTowncrier {ReadOnlyTimer _timer;  PublicTowncrier () {_timer=NewTimer ( the) {AutoReset =true }; _timer. Elapsed+ = (sender, EventArgs) = Console.WriteLine ("It's {0} and all are well", DateTime.Now); }         Public voidStart () {_timer. Start (); }         Public voidStop () {_timer. Stop (); }    }

5. Safety Loading method:

Installation: TopshelfDemo.exe Install

Start: TopshelfDemo.exe start

Uninstall: TopshelfDemo.exe Uninstall 6. When the installation is complete, you can see it in the Windows service.

Create a Windows service using Topshelf

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.