Threads -> delgates -> returning a value to the thread that calledthe function

  • Thread starter Thread starter Devin
  • Start date Start date
D

Devin

Obviously there is a way to do this but I have been unsuccessful in my
searching. I'm not sure what exactly I should be searching for.

Sub handleThread()
Me.Invoke(New EventHandler(AddressOf login))
End Sub


Is there a way I can get it so login returns a value?

I would expect this to work:

Sub handleThread()
dim val as integer
val = Me.Invoke(New EventHandler(AddressOf login))
End Sub


function login()
return 8
end function



I'm not sure how to do it or if I have been doing something wrong from
the get-go. Advise?
 
Devin said:
Obviously there is a way to do this but I have been unsuccessful in my
searching. I'm not sure what exactly I should be searching for.

Sub handleThread()
Me.Invoke(New EventHandler(AddressOf login))
End Sub


Is there a way I can get it so login returns a value?

I would expect this to work:

Sub handleThread()
dim val as integer
val = Me.Invoke(New EventHandler(AddressOf login))
End Sub


function login()
return 8
end function



I'm not sure how to do it or if I have been doing something wrong from
the get-go. Advise?

The delegate 'EventHandler' is not a Function delegate (returning a value).

This works:

Private Delegate Function loginDelegate() As Integer

Sub handleThread()
Dim val As Integer
val = DirectCast( _
Me.Invoke(New loginDelegate(AddressOf login)), Integer _
)
End Sub

Function login() As Integer
Return 8
End Function


Armin
 
Devin said:
Obviously there is a way to do this but I have been unsuccessful in my
searching.

Take a look at the documentation on the 'IAsyncResult' interface.
 
Armin Zingler said:
The delegate 'EventHandler' is not a Function delegate (returning a
value).

This works:

Private Delegate Function loginDelegate() As Integer

Sub handleThread()
Dim val As Integer
val = DirectCast( _
Me.Invoke(New loginDelegate(AddressOf login)), Integer _
)
End Sub

Function login() As Integer
Return 8
End Function

.... but 'handleThread' will be blocked until the value is returned. In
addition, 'Me.Invoke' will cause the method to be executed in the context of
the thread the form has been created on (typically the main UI thread).
 
Herfried said:
... but 'handleThread' will be blocked until the value is returned.
In addition, 'Me.Invoke' will cause the method to be executed in the
context of the thread the form has been created on (typically the
main UI thread).

Sure, but the problem was how to return a value which is done now.


Armin
 
Back
Top