最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论