In VS Code, I have a task which starts a web server, so the task will never terminate by itself.
Now, when I kick off the task again, I get the following dialog box:
How can I avoid this message and tell VS Code to automatically restart the task (i.e. first terminate the old invocation and then start the task again) without me clicking "Restart Task" in the dialog box. (Is there maybe an extension which can do this?)
You can write a keybinding to kill all running tasks, and even do that and then start a new task. For example:
{
"key": "<your-keyboard-shortcut-here>", // TODO
"command": "runCommands",
"args": {
"commands": [
{
"command": "workbench.action.tasks.terminate",
"args": "terminateAll"
},
{
"command": "workbench.action.tasks.runTask",
"args": {
"task": "<your-task-name-here>", // TODO
}
}
]
}
}
Inspiration for this workaround came from here.
See Add a task instancePolicy to task runOptions. #90125, which- once implemented- will allow you to write the following in your task specification:
"runOptions": {
"instanceLimit": 1, // default is 1 if unspecified
"instancePolicy": "terminateOldest" // or "terminalNewest" or "prompt"
}
, which will cause VS Code to terminal any still-running, previous instance of the task before running a new one of it.
The issue ticket is in the "On Deck" milestone. You can give it a thumbs up reaction to show support for it, and subscribe to it to get notified about discussion and progress. You can show your support for the issue ticket by giving a thumbs up reaction to the issue. But please don't make a "me too" comment. "me too" comments generally come off as annoying to repo maintainers because they clutter up discussion and don't contribute anything of significant value.
For your reference / learning purposes, that issue ticket was linked to in one of the top search results when googling "github vscode issues always restart task prompt
": No option to automatically terminate previous task when a new instance of the same task is started
#32264.