added ui enabled check before displaying dialogs
added wait to make sure main thread does not exit when there's no display