Share via

MessageBox in Thread

OSVBNET 1,401 Reputation points
2022-05-16T14:03:30.127+00:00

Hello,
Inside a thread I should invoke my MessageBoxEx to show it as MODAL:

If Invoke(New QuestionBoxHandler(AddressOf ShowQuestionBox), "Query?") = vbYes Then...
::
Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity.

If I replace = with Is:
'Is' operator does not accept operands of type 'Microsoft.VisualBasic.MsgBoxResult'. Operands must be reference or nullable types.

Private Delegate Function QuestionBoxHandler(ByVal Message As String) As DialogResult
Private Function ShowQuestionBox(ByVal Message As String) As DialogResult
ShowQuestionBox = MessageBoxEx.Show(Message, "TITLE", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
End Function

Any idea how to fix this error? :(

Developer technologies | VB
0 comments No comments

Answer accepted by question author

Viorel 127K Reputation points
2022-05-16T14:30:32.88+00:00

Try this:

If CType(Invoke(New QuestionBoxHandler(AddressOf ShowQuestionBox), "Query?"), DialogResult) = DialogResult.Yes Then
   . . .
End If

or this:

If Equals(Invoke(New QuestionBoxHandler(AddressOf ShowQuestionBox), "Query?"), DialogResult.Yes) Then
   . . .
End If

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.