Manipulating Background task queue

I have a JList in my toolwindow and when I click on each row, a background process is run and on completion another part of my toolwindow is populated with the content. I am using ProgressManager.getInstance().run() to achieve the background process. This works perfectly. Now, when I click on a row and then click on another row and so on (like for 6 times), for each click a backgroud process is run (6 process). This is not what I want.

Once the user clicks on one row and immediately clicks on 2nd row, I want to cancel the first process and move on the 2nd one. So if there are 6 clicks done, I am only concered about the result of the 6th process. Hence I wish to remove all the other process from the queue.

1) Can this be done in the IntelliJ API, or should I manually take care of the queuing part.
2) Is there any way to get a list of all the background processes and kill the ones I don't want ?
3) Does ProgressManager.getInstance().run() queues the tasks, or does it run eveything in parallel? If not, what API does the background processes in a queue ?

1 comment
Comment actions Permalink

To run multiple background tasks in a sequence, you can use the BackgroundTaskQueue class.

If you want to stop a task, the task itself should check for a flag requesting it to stop. You can either use the standard ProgressIndicator.checkCanceled() API for this purpose, or come up with your own API.

Since you're starting the background processes yourself, you should also keep track of the processes you've started yourself, and stop the ones you don't need.

0

Please sign in to leave a comment.