This article is a mirror article of machine translation, please click here to jump to the original article.

View: 22590|Reply: 3

[Console Program] The use of Topshelf for C# scheduled execution tasks

[Copy link]
Posted on 4/27/2019 9:28:16 PM | | | |
preface

Following the previous article on Creating Windows Services, this article will record a simpler way to create Windows services. Use Topshelf third-party plugins.
Environment & Tools

>Windows 10 system

>VS 2017

Text

1: Create a new console application.

2: Install "Topshelf", and quoted. You can also click on the link to download (The hyperlink login is visible.

3: Paste the following code:






4: F5 runs the program, and you can see that every second it outputs a line.




5: In line 6, write Ctrl +C to exit. So we stop.




Installation services

We have already implemented timed tasks with Topshelf earlier. Let's install it into a service.

1: For the code part, you can refer to the previous article. In the start() stop() method, record the information. In this way, in the subsequent installation, you can see the program running more intuitively.

2: First, open CMD as an administrator. Then use the command line to cut to the directory where the program is running ("bin\Debug").






3: Start installing the service. Enter "TopshelfDemo.exe install" on the command line - > enter.





4: You can see the installation is successful in the picture above. Now start the service, enter "TopshelfDemo.exe start" – > enter.





5: You can see that the service has been successfully started in the figure above. One of the features of Topshelf is that you can deploy the same instance under several different names.

Then enter "TopshelfDemo.exe –instance "newinstallname" install" - > enter.






Start the service with this new name, enter "TopshelfDemo.exe –instance "newinstallname" start" – > enter.


6: You can see that the second instance is also installed successfully. Now let's check the service status.



The service can be seen, two instances are started.

7: Stop Service Enter "TopshelfDemo.exe stop" – > enter.




Uninstall Service Enter "TopshelfDemo.exe uninstall" – > enter.





8: Uninstall the instance of the second installation with similar syntax The command line is:


Epilogue

Topshelf is better with Quartz.Net for scheduled service.





Previous:C# is a Windows service that executes tasks regularly
Next:Proficient in advanced RxJava 2 responsive programming ideas
Posted on 4/30/2019 12:08:19 AM From the phone |
Wow, Fat Chan, you're so great, I still posted a water tip to you in the middle of the night
 Landlord| Posted on 4/30/2019 3:19:53 PM From the phone |
Jiu Shiya Posted on 2019-4-30 00:08
Wow, Fat Chan, you're so great, I still posted a water tip to you in the middle of the night

Pfft. I didn't sleep in the middle of the night, looking at the technical post?
Posted on 5/14/2019 6:33:13 PM |
Empty Cicada Posted on 2019-4-30 15:19
Pfft. I didn't sleep in the middle of the night, looking at the technical post?

That's for sure, after all, are you a role model?
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com