Run a task in Background and Wait for result
Answered
Hello,
I am developing a plugin that runs a task which takes about 2-3 minutes to execute. After that, it should display results in tabular format in the ToolWindow.
I want to run this task in background and once the task is complete, I want to create and populate the table in toolWindow.
This is the code below. The timer is just for testing.
val progressManager = ProgressManager.getInstance()
val progressIndicator = progressManager.progressIndicator
progressManager.runProcessWithProgressAsynchronously(object :Task.Backgroundable(project!!,"Title",true){
override fun run(indicator: ProgressIndicator) {
Thread.sleep(5_000)
}
},progressIndicator)
Then, I want to check the progress indicator using a while loop till the task is complete using
progressIndicator.isRunning
But, I do not understand how to instantiate ProgressIndicator properly and If my approach is correct. Please let me know how to achieve this.
Please sign in to leave a comment.
There are several methods to override in Task, e.g. com.intellij.openapi.progress.Task#onSuccess/onCancel/onError