2

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.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

KeentoLearn
  • 355
  • 1
  • 4
  • 12
  • 1
    The task is taking longer than 5 minutes to run? `If the task is already running, then the following rule applies: Do not start a new instance` – Dabombber Dec 21 '20 at 10:12
  • @Dabombber, I am not sure what are you talking about. If you see the rule in the setting, it is `Do not start a new instance` selected. Please elaborate on your comment. – KeentoLearn Dec 21 '20 at 20:38
  • Yes. The warning you are getting is that there is an instance running and it won't start another one, because you have set it to not start a new instance if it is already running. The problem is that your task is still running for some reason, which we can't help with since you have not given any details about it. – Dabombber Dec 22 '20 at 07:33
  • @Dabombber, I have included some more screenshots. Please have a look and suggest some possible solutions. The same setting works in the development server. – KeentoLearn Dec 22 '20 at 09:17

4 Answers4

0

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.

YHS
  • 137
  • 9
0

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

Task scheduler

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\"
0

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.

enter image description here

Fandango68
  • 4,461
  • 4
  • 39
  • 74
0

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();
   }
Amir
  • 1,855
  • 3
  • 24
  • 40