Reputation: 3756
I've been messing around with the answer given here How to update the GUI from another thread in C#?
I'm getting the error Method 'System.Windows.Forms.Label' Text not found from the following code
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
From a separate thread I calling this method with the following line
UI.setControlPropertyThreadSafe(UI.lblExcel, "Text", "Inserting Data into YTD Template")
Any help regarding this error will be much appreciated.
Upvotes: 0
Views: 101
Reputation: 31404
The line
control.GetType().InvokeMember(propertyName, Reflection.BindingFlags.SetProperty, _
Nothing, control, New Object() {control, propertyName, propertyValue})
Should be
control.GetType().InvokeMember(propertyName, Reflection.BindingFlags.SetProperty, _
Nothing, control, New Object() {propertyValue})
The last parameter to InvokeMember
is the parameter list for the method, which for a property setting is just the value you wish to set. The question you linked to has it correct.
Upvotes: 3