Reputation: 127
In my plugin, I execute a network query, get the result and show the processing step.
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
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