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 badge1 Answer
Reset to default 1You 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 badge1 Answer
Reset to default 1You 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
版权声明:本文标题:return - vb.net Invoke not returning proper values? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745640065a2160692.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论