Reputation: 355
I am scratching my head for the last 2 days because of this issue. This error is intermittent on the production server as sometimes the task scheduler works and sometimes not.
The same settings work in the development server.
I also checked the execution policy on both servers and it looks the same.
Upvotes: 2
Views: 15623
Reputation: 1
For me i the task was continues running but not executing the script. What helped me was changing the following setting and keep everything else default.
In Action tab filled in follwing:
for Program/script: Powershell add arguments (optional): Powershell-executionpolicy bypass -File E:[path to script]\scriptname.ps1
Upvotes: 0
Reputation: 2052
Solution that work for me
Inject IHostApplicationLifetime
public class CoreHostService : IHostedService
{
private readonly IHostApplicationLifetime _hostApplicationLifetime;
CoreHostService(IHostApplicationLifetime hostApplicationLifetime)
{
_hostApplicationLifetime = hostApplicationLifetime;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
...
//do something
...
_hostApplicationLifetime.StopApplication();
}
Upvotes: 0
Reputation: 4898
Do yourself a favor and save your hair on your head! Just set all task scheduler jobs as follows, and you'll never have issues with these ridiculous "warnings".
Don't tick anything else. The design of this program was poorly tested IMO.
Upvotes: 2
Reputation: 53
I had almost this exact problem where running a command line app from command line would work, but not when running it as scheduled task.
It turned out the scheduled task is quite sensitive on the fact that parameters must be passed as parameters and not be part of the target .exe.
So if there is anyone other struggling with this kind of problem, make sure you have your command line parameters as parameters (see the picture attached).
Also if you like to make your scheduled task using PowerShell scriptin you can do this like:
$action = New-ScheduledTaskAction -Execute "c:\temp\myApp.exe" -Parameters "testConnection true" -WorkingDirectory "c:\tempFiles\"
Upvotes: 0
Reputation: 157
In your second screenshot, you can choose "Stop existing instance" in the latest dropdown list (if the task is already running). Then the retry option might trigger your task again correctly.
Upvotes: 1