Application.DoEvents and MessageBox
If the user clicks ‘Yes’, the following will close the messagebox first before doing any other thing.
Private Sub TestMsgBox()
If MessageBox.Show(“Do Work?”, “Confirm?”) = Windows.Forms.DialogResult.Yes Then
‘this close the MessageBox first
Application.DoEvents()
‘start to do work
……………..
End If
End Sub
Without the call to Application.DoEvents (), the messagebox will still be visible after the user clicks Yes; it will only be closed after the Sub has finished.
An alternative is to do the work in a separate thread.