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

View: 9168|Reply: 1

Use Powershell in conjunction with the .NET core console program to perform scheduled run tasks

[Copy link]
Posted on 4/18/2019 1:03:50 PM | | | |
Recently, there was a need to make a Windows Service service to execute regularly, and after writing it with net core, I found that it could not be run as a service.

After searching in the garden, there are various solutions, each with its own merits. After reading it, I felt that it was not very convenient, so I thought of my own ideas to deal with it. The final solution is to write three or four lines of code in posershell, and as soon as it is executed, the scheduled task can be successfully added

First of all, write a net core console program. The console program runs your processing logic.



The code doesn't show ......

Then publish the code to the folder of Zhibao, and you need to record the dll name of your console. Yes, the dll name, the NET Core console program, does not create an exe file by default.

Copy the published folder path,

The following code can be written in any editor, I wrote it using the system's built-in Powershell ISE.





Code to illustrate,

Register a scheduled task (Register-ScheduledJob) in the system, specify the schedule name (-Name), specify the script to run (-ScriptBlock), script content (dotnet path),

Specify a trigger (-Trigger), create a new trigger Specify the start time of the run, specify the interval between runs (-RepetitionInterval), run once an hour (01:00:00), and specify an indefinite run (-RepeatIndefinitely)

Just run the Powershell script above to add a scheduled task to the system.

Simple and convenient enough.

Unregister-ScheduledJob -Name XXXXService --- Delete the scheduled task.





Previous:Tomorrow Academy Zero Foundation Learning Android Digital Book
Next:WPF Programmer Rest Digital Clock [with source code]
Posted on 5/15/2019 11:38:25 AM |
Learned,
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