How to correctly use ProgressDialog around a WriteAction
Hello, I can't get the threading correct for my WriteAction correctly working with ProgressDialog.
What I want: show a ProgressDialog while running ReadAction, WriteAction, and commits.
What's happening: I either get a PD showing but also threading errors from my WriteAction or I get no PD showing but writes do occur.
My code looks something like this (simplified, full code on my GitHub):
ProgressManager.getInstance().runProcessWithProgressSynchronously(
{ doWork(ProgressManager.getInstance().progressIndicator.modalityState) },
...)
private fun doWork(modalityState: ModalityState) {
val app = ApplicationManager.getApplication()
val elementsToModify = app.runReadAction<List<PsiElement>> { find() }
app.invokeLater(
{
executeCommand(project = project) {
app.runWriteAction {
elementsToModify.forEach {
writeModifications(it)
it.containingFile.commitAndUnblockDocument()
}
}
}
},
modalityState
)
}
Thanks,
Harold
请先登录再写评论。