Threads: Invoke cause an InvalidCastException

45 views Asked by At

I want to return the text of a textbox. This worked. But calling the function with the before determined parameter cause an InvalidCastException. Visual Studio says that converting from IAsyncResult to FileInfo (searchEnginePower returns this) could cause runtime errors.

    Dim result As IAsyncResult = Me.BeginInvoke(Function() As String
                                                    Return PropABCtool.PropTextbox1
                                                End Function)
    Dim a As FileInfo = Me.BeginInvoke(Sub() PropABCtool_.PropCar.searchEnginePower(Me.EndInvoke(result)))
    If a IsNot Nothing And a.Exists Then 
    ...

    End If

How can I solve the exception?

1

There are 1 answers

0
jmcilhinney On

You haven't really provided all the relevant information but, from what I can tell, you should be doing this:

Dim a As FileInfo = Me.Invoke(Function() PropABCtool_.PropCar.searchEnginePower(PropABCtool.PropTextbox1))