Hi folks
The MDSN page for the Control.Invoke method specifies:
Control.Invoke Method (Delegate)
Now I was given in my admittedly limited knowledge to understand that a delegate is just a variable that holds a reference to a function or sub and using a lamda in place ends up passing the same thing when used as a parameter; a reference to a function. (I think of this as similar to passing function pointers in C and a lambda parameter just passes a pointer for a function that's written as an argument)
This could be where the following confusion stems from I guess but here goes:
The argument is asked for as a delegate. Using 'SomeControl.Invoke(Sub() somesub(someargs))' works fine. seems to me that's because the argument is a lambda that is a Sub that calls some other sub.
Yet trying trying to use a Function lambda or a multi-line lambda does not work because (and here's the screen head-butting bit) "the expression does not produce a value"
...
But a lamda produces a value surely, the reference to the anonymous function?
And if not then how did the original single line Sub lambda work? If lambdas don't fulfil this requirement then how can any form of them work at all? Seems like it is supposed to take delegates but only works for particular types of them or when they're declared in particular ways??
Anyway what I'd like to end up with is being able to go:
vb Code:
SomeControl.Invoke(Sub()
Foo()
If (Something) then
Bar()
End If
End Sub)
Instead of
vb Code:
Private Sub StupidHelperSub()
Bar()
If (something) Then
Foo()
End If
End sub
...
SomeControl.Invoke(Sub() StupidHelperSub())