fix some bugs in multi-threading, now we can close the dialog while refreshing