I am trying to show a message box when an error occurs in a modal dialog window but for some reason the message box is never shown although I know the MessageBox.Show method is being hit. The try catch block is inside of an event handler for a windows form that is being shown as a modal dialog. I know that the event is being fired and that the error is being caught but the message box never opens. I've replaced the MessageBox.Show with another form show and it works fine but I'd rather use MessageBox instead of creating my own error form. I just can't seem to make MessageBox work. Is this a limitation of MessageBox?
Here is a simplified version of what I am doing:
Private Sub OnSomeEvent(ByVal args As MyEventArgs)
Try
'some processing
Catch ex As Exception
ShowMessage("An error has occurred")
End Try
End Sub
Private Delegate Sub _showMessage(ByVal message As String)
Private Sub ShowMessage(ByVal message As String)
If Me.InvokeRequired Then
Me.Invoke(New _showMessage(AddressOf ShowMessage), message)
Else
MessageBox.Show(message, "ERROR")
'also tried MessageBox.Show(Me, message) but no luck
End If
End Sub
*side note: In this case I do not need the InvokeRequired section of ShowMessage but I left it in for completeness (in case somehow that could be causing the issue). I have it there for other cases when it is called from a background thread. In this particular instance when debugging, it goes through the Else branch.