How to close dialog before performing an action?

Maybe this thread would help: Showing A Yes No Cancel Message Box - #6 by simonhenke