Vb.net 从单独的线程读取UI时出现问题
我一直在胡思乱想这里给出的答案 从以下代码中找不到错误方法“System.Windows.Forms.Label”文本Vb.net 从单独的线程读取UI时出现问题,vb.net,winforms,multithreading,user-interface,Vb.net,Winforms,Multithreading,User Interface,我一直在胡思乱想这里给出的答案 从以下代码中找不到错误方法“System.Windows.Forms.Label”文本 Private Delegate Sub setControlPropertyThreadSafeDelegate(control As Control, propertyName As String, propertyValue As Object) Public Sub setControlPropertyThreadSafe(control As Control, p
Private Delegate Sub setControlPropertyThreadSafeDelegate(control As Control, propertyName As String, propertyValue As Object)
Public Sub setControlPropertyThreadSafe(control As Control, propertyName As String, propertyValue As Object)
If control.InvokeRequired = True Then
control.Invoke(New setControlPropertyThreadSafeDelegate(AddressOf setControlPropertyThreadSafe), New Object() {control, propertyName, propertyValue})
Else
control.GetType().InvokeMember(propertyName, Reflection.BindingFlags.SetProperty, Nothing, control, New Object() {control, propertyName, propertyValue}) 'This is where the error occurs
End If
End Sub
从一个单独的线程中,我用下面的行调用这个方法
UI.setControlPropertyThreadSafe(UI.lblExcel, "Text", "Inserting Data into YTD Template")
对于有关此错误的任何帮助,我们将不胜感激。该行
control.GetType().InvokeMember(propertyName, Reflection.BindingFlags.SetProperty, _
Nothing, control, New Object() {control, propertyName, propertyValue})
应该是
control.GetType().InvokeMember(propertyName, Reflection.BindingFlags.SetProperty, _
Nothing, control, New Object() {propertyValue})
InvokeMember
的最后一个参数是该方法的参数列表,对于属性设置,它正是您希望设置的值。你链接到的问题是正确的。行
control.GetType().InvokeMember(propertyName, Reflection.BindingFlags.SetProperty, _
Nothing, control, New Object() {control, propertyName, propertyValue})
应该是
control.GetType().InvokeMember(propertyName, Reflection.BindingFlags.SetProperty, _
Nothing, control, New Object() {propertyValue})
InvokeMember
的最后一个参数是该方法的参数列表,对于属性设置,它正是您希望设置的值。您链接的问题是正确的。非常感谢您的回答。我明天上班的时候会查的。非常感谢你的回复。我明天上班时再查。