method to dismiss dialog on UI thread.