One method to call code on a regular interval, such as might be the case when you want to routinely run a maintenance call to clear log files or to check for the execution of a custom-built workflow, would be to invoke a web service via a PowerShell script that is set to be called on a timed schedule via Windows Task Scheduler.
By creating a PowerShell script using the “Invoke-WebRequest” command you can execute any waiting code accessible over a URL including an asynchronous web service. This allows for the flexibility of centralizing your code base to an already deployed project but gives you the flexibility of running it on your schedule as if it were in essence a timed Windows service.
In the Action of the Scheduled Task you will need to call to “powershell.exe” and provide a path to the script file (typically a .ps1 file). Please keep in mind that under the Scheduled Task “Settings” tab you will want to be certain to check “Do not start a new instance” of the task if it is already running. Due to the nature of the Task Scheduler, the PowerShell execution and possibly the asynchronous service being called, the scheduler may try to re-run the task if it is uncertain of the completion status which could lead to undesirable redundancy.
For more server tips and tricks please reach out to our development team. Contact us for a free consultation today.