Code Repo    |     RSS
MD's Technical Sharing



Wednesday, April 1, 2009

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.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.