【问题标题】:VSCode terminate task by nameVSCode 按名称终止任务
【发布时间】:2018-10-30 01:24:51
【问题描述】:

我创建了一个 VSCode 扩展,并通过它的名称成功运行了一个任务,例如:

vscode.commands.executeCommand("workbench.action.tasks.runTask", "task_name_here");

现在,当我尝试按名称终止该任务时,UI 不断要求我手动选择任务:

vscode.commands.executeCommand("workbench.action.tasks.terminate", "task_name_here");

有没有办法实现这个?

【问题讨论】:

    标签: visual-studio-code vscode-extensions vscode-tasks


    【解决方案1】:

    As of VSCode 1.24,有一个 API 可以让你做到这一点。您可以为正在启动/结束的任务等事件注册事件侦听器,并且这些事件都包含一个 TaskExecution 实例。最重要的是,有一个包含所有当前执行的只读列表。执行被定义为this:

    /**
     * An object representing an executed Task. It can be used
     * to terminate a task.
     *
     * This interface is not intended to be implemented.
     */
    export interface TaskExecution {
        /**
         * The task that got started.
         */
        task: Task;
    
        /**
         * Terminates the task execution.
         */
        terminate(): void;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-05-01
      • 1970-01-01
      • 2013-10-14
      • 1970-01-01
      • 2015-03-11
      • 1970-01-01
      • 1970-01-01
      • 2013-03-12
      • 1970-01-01
      相关资源
      最近更新 更多