Task Scheduler did not launch task "\abc" because instance "(GUID)" of the same task is already running

9.6k Views Asked by At

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

4

There are 4 best solutions below

0
YHS On

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.

0
Matti Lindroth On

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
Fandango68 On

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

0
Amir On

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();
   }