Intellij idea 经理。取消按钮

Intellij idea 经理。取消按钮,intellij-idea,intellij-plugin,Intellij Idea,Intellij Plugin,在我的插件中,我执行一个网络查询,得到结果 并显示处理步骤 有时查询由网络执行很长时间,我想停止使用all块(runnable块)。 为此,在runprocesswithprogressynchronously中,我传递了参数canbecancelled=true 天真地认为这个想法会停止执行我的可执行块,但这并没有发生 如何捕捉取消按钮的点击并停止我的可运行块?您需要定期从块中调用ProgressIndicator.checkcancelled()。如果按下取消按钮,此方法将抛出一个Proc

在我的插件中,我执行一个网络查询,得到结果 并显示处理步骤

有时查询由网络执行很长时间,我想停止使用all块(runnable块)。 为此,在
runprocesswithprogressynchronously
中,我传递了参数
canbecancelled=true
天真地认为这个想法会停止执行我的可执行块,但这并没有发生


如何捕捉取消按钮的点击并停止我的可运行块?

您需要定期从块中调用
ProgressIndicator.checkcancelled()
。如果按下取消按钮,此方法将抛出一个
ProcessCanceledException

CoreProgressManager.getInstance().runProcessWithProgressSynchronously(Runnable {
        //runnable block
        CoreProgressManager.getInstance().progressIndicator.text  = "Start loading"
        val result = MyProvider.getObjects() // this network request
        CoreProgressManager.getInstance().progressIndicator.text  = "Finish"
        result.forEach {
            //processing result
            CoreProgressManager.getInstance().progressIndicator.text  = "Processing is $result"
        }
    }, taskTitle, true /* canBeCanceled */, project)