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.
|