In a AsyncCallBack Procedure, I need to change the enabled property of the button to false. I tried using Reflection.Prop ertyInfo.
The Code goes like this
Expand|Select|Wrap|Line Numbers
- Dim pi As System.Reflection.PropertyInfo = btnLogin.GetType.GetProperty("Enabled")
- pi.SetValue(btnLogin, False, Nothing)
Exception has been thrown by the target of an invocation.
System.InvalidO perationExcepti on: Cross-thread operation not valid: Control 'btnLogin' accessed from a thread other than the thread it was created on.
at System.Windows. Forms.Control.g et_Handle()
at System.Windows. Forms.Control.O nEnabledChanged (EventArgs e)
at System.Windows. Forms.ButtonBas e.OnEnabledChan ged(EventArgs e)
at System.Windows. Forms.Control.s et_Enabled(Bool ean value)
But if I create a button control on runtime and try to assign property using reflection, then there is no error.
Please let me know
how can I refer the instance of the btnLogin button created in the form at desing time into a
runtime created button object.
Thanks in advance.