admin管理员组

文章数量:1025754

I'm interacting with GUI controls from a separate thread when invoked i'm always getting a "nothing" object despite what I think is the right code? Not sure where it's breaking. the second to last line of code "ListView1.FindItemWithText(value)" work on it's own 100% confirmed but not in the context when being invoked

Public Function listview1FindItemWithText(ByVal value As String) As ListViewItem
If InvokeRequired Then
    Return CType(Me.Invoke(New Action(Of String)(AddressOf listview1FindItemWithText), value), ListViewItem)
End If

Return ListView1.FindItemWithText(value)
End Function

I tried lots of changes but the invoked version always returns nothing

I'm interacting with GUI controls from a separate thread when invoked i'm always getting a "nothing" object despite what I think is the right code? Not sure where it's breaking. the second to last line of code "ListView1.FindItemWithText(value)" work on it's own 100% confirmed but not in the context when being invoked

Public Function listview1FindItemWithText(ByVal value As String) As ListViewItem
If InvokeRequired Then
    Return CType(Me.Invoke(New Action(Of String)(AddressOf listview1FindItemWithText), value), ListViewItem)
End If

Return ListView1.FindItemWithText(value)
End Function

I tried lots of changes but the invoked version always returns nothing

Share Improve this question edited Nov 17, 2024 at 2:36 Michal Bogs asked Nov 17, 2024 at 2:32 Michal BogsMichal Bogs 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

You are creating an Action delegate, which is specifically for methods that don't return a value, i.e. a Sub. If no value is returned by the delegate, you get Nothing returned by Invoke. If you want to invoke a Function then you should be creating a Func delegate. In this specific case, you need a Func(Of String, ListViewItem).

I'm interacting with GUI controls from a separate thread when invoked i'm always getting a "nothing" object despite what I think is the right code? Not sure where it's breaking. the second to last line of code "ListView1.FindItemWithText(value)" work on it's own 100% confirmed but not in the context when being invoked

Public Function listview1FindItemWithText(ByVal value As String) As ListViewItem
If InvokeRequired Then
    Return CType(Me.Invoke(New Action(Of String)(AddressOf listview1FindItemWithText), value), ListViewItem)
End If

Return ListView1.FindItemWithText(value)
End Function

I tried lots of changes but the invoked version always returns nothing

I'm interacting with GUI controls from a separate thread when invoked i'm always getting a "nothing" object despite what I think is the right code? Not sure where it's breaking. the second to last line of code "ListView1.FindItemWithText(value)" work on it's own 100% confirmed but not in the context when being invoked

Public Function listview1FindItemWithText(ByVal value As String) As ListViewItem
If InvokeRequired Then
    Return CType(Me.Invoke(New Action(Of String)(AddressOf listview1FindItemWithText), value), ListViewItem)
End If

Return ListView1.FindItemWithText(value)
End Function

I tried lots of changes but the invoked version always returns nothing

Share Improve this question edited Nov 17, 2024 at 2:36 Michal Bogs asked Nov 17, 2024 at 2:32 Michal BogsMichal Bogs 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

You are creating an Action delegate, which is specifically for methods that don't return a value, i.e. a Sub. If no value is returned by the delegate, you get Nothing returned by Invoke. If you want to invoke a Function then you should be creating a Func delegate. In this specific case, you need a Func(Of String, ListViewItem).

本文标签: returnvbnet Invoke not returning proper valuesStack Overflow