Run a task in Background and Wait for result



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) {

Then, I want to check the progress indicator using a while loop till the task is complete using 


But, I do not understand how to instantiate ProgressIndicator properly and If my approach is correct. Please let me know how to achieve this.

1 comment

There are several methods to override in Task, e.g. com.intellij.openapi.progress.Task#onSuccess/onCancel/onError


Please sign in to leave a comment.