fix window closing

Add try ... catch statement to catch InvalidOperationException throwed by window if failed to set DialogResult