2

Overview:

I use Windows Task Scheduler to run automated tasks. Occasionally I will see that randomly a task has failed to perform its duties. When I check Task Scheduler to see what has occurred in the history log, I see that for some reason, when the tasks are triggered at their schedules, they are spawning several instances of themselves simultaneously which turns into a train wreck for the task and it either kills the other instances and tries to run the "first" one, or it just does not run at all as it believes another instance of itself is already running. Sometimes this occurs in the same tasks and then occasionally it happens with others. The fix is just to end all instances and start the task manually.

Question:

Why would one single task with one single schedule decide to spawn multiple instance of itself simultaneously?

Note:

I've got a separate user account set to run the tasks instead of myself. That user is indeed an admin on the machine that runs the tasks and the tasks are set to tun whether or not the user is logged on. Also, the machine is windows server 08 R2.

1
  • Is this an exe file set to execute, or a batch file? How often is it set to execute, every 15 minutes, every hour, daily? You might also check the c:\windows\Tasks\SCHEDLGU.TXT to see if you find anything to note from that.
    – Nixphoe
    Jun 2, 2011 at 19:14

4 Answers 4

3

There is a known bug with task scheduler that will cause it to run the same task twice from time to time. It happens when the previous scheduled task terminates exactly when the new task is supposed to start: the scheduler will then run the same task twice.

There is a hotfix available there: http://support.microsoft.com/kb/2461249

When we ran into that problem, we fixed it simply by making the task run less frequently.

1

I have been experiencing this issue on Windows Server 2012 R2, the machine hosts a scheduled task that is supposed to run every 15 minutes and is responsible for moving files off of an SFTP Server.

The duplicate instance has been occurring for some time and I have only just been able to figure out a workaround.

I wrapped my scheduled task in a PowerShell start-process command, and used a mutex to provide a block on the thread ensuring that only a single instance of my task can run.

Here is how i achieved this in code

# Start mutual exclusion
$Mutex = New-Object -TypeName System.Threading.Mutex -ArgumentList $false, "Global\**MyMutexName**"
$Mutex.WaitOne() | Out-Null

    ***..... Rest of my code here .....***

#Release the mutal exclusion
$Mutex.ReleaseMutex() | Out-Null

I also updated the scheduled task action to launch my powershell script and pass the -sta argument to launch with sta mode enabled.

I do see multiple instances being spawned through the task scheduler history, both have different correlation id's however one of them fails to launch and the other completes successfully.

Scheduled Task History Screenshot

I do hope that this answer helps someone in the future as i have spent many months trying to find a solution to this!

1
  • BTW i migrated to Windows Server 2019 and the issue went away, seems maybe a bug with task scheduler 2012, maybe the schedule registry is corrupt. Cant confirm tho as the server decommissioned now. Dec 15, 2021 at 10:00
0

The task scheduler has an option of restarting a task if it thinks the first start was not successful. If the option is set, it would be a good idea of disabling it. Some further examination as for why the first start returns a non-successful value should follow.

Could you post what exactly you are starting and if it is a script of some sort include the source code of the script as well?

0

I had a few of these Tasks that seemed to spawn multiple times at almost the exact same moment. Others did not. I solved it this way:

1) Go to the Task Properties

2) On the Settings tab, ensure that the item at the bottom - "If the task is already running, then the following rule applies:"

3) is set to - "Do not start a new instance"

Finally, it behaved like a good little Task and only ran the one bloody time I wanted it to. Goooood Task. You get biscuit.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .