return - vb.net Invoke not returning proper values? - Stack Overflow

I'm interacting with GUI controls from a separate thread when invoked i'm always getting a &q

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).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745640068a4637637.html

相关推荐

  • return - vb.net Invoke not returning proper values? - Stack Overflow

    I'm interacting with GUI controls from a separate thread when invoked i'm always getting a &q

    22天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信