It can happen that a task that runs as scheduled task simply does not terminate. Whether this is a fault of task manager or the script is unknown, but both can be at fault here. For example, if the batch file contains a pause statement, the batchfile expects a keypress to continue. The task scheduler will never send it, and this the script never finishes.
That being said, I've seen occasions where a task finishes normally, yet task scheduler does not recognize this to be the case. The script terminates normally, yet task manager claims its still running.
For this reason, Microsoft enabled the option to terminate a task after x hours if its still running.
So what you want to do is edit the task, go to the settings tab and find the Stop the task if it runs longer than 3 days
and change this to 1 hour.
At the bottom, you will find: If the task is already running, the following applies: Do not start a new intstance
.
Change this to Run a new instance in parallel
.
Notice that this option has the ability to kill the previous task or queue. I deliberately choose not to utilize this method.
Now, once you save the settings, right click the task and choose stop
to stop the running instance.
Keep in mind, if the script really is at fault here, it may be the case that it does not run normally and thus whatever it is supposed to do never is being done. For example, if you run your script without task scheduler and it works, and does some stuff on network shares, and now you configure to do this with task scheduler, but you run it with higher privileges, it may simply not have access to the network shares and fails for that reason. That should however terminate the script normally though.
But will it start a new instance again after 1 hour @LPChip ? – Rajdeep Nandi – 2016-07-28T10:17:38.317
It will if your triggers are set up to do so. – LPChip – 2016-07-28T10:30:43.640
Hi @LPChip , your solution worked perfectly for me...but could you please tell if there will be any impact on the application later on? – Rajdeep Nandi – 2016-07-29T06:01:02.240
I'm sorry, but this is a question I can't impossibly answer as I know nothing about the application. Using task scheduler to run a script will always impact the system very little, but if its going to be a problem, I can't tell. – LPChip – 2016-07-29T12:02:28.200