Interrobang
Interrobang

Reputation: 127

ProgressManager. Cancel button

In my plugin, I execute a network query, get the result and show the processing step.

enter image description here

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)

Sometimes the query is performed by the network for a long time, and I want to stop working all block (runnable block). For this, in runProcessWithProgressSynchronously I passed the parameter canBeCanceled = true and naively thought that IDEA would stop executing my executable block, but this did not happen.

How do I catch the clicking of a Cancel button and stop my runnable block?

Upvotes: 1

Views: 303

Answers (1)

yole
yole

Reputation: 97258

You need to periodically call ProgressIndicator.checkCanceled() from your block. This method will throw a ProcessCanceledException if the Cancel button has been pressed.

Upvotes: 2

Related Questions