How to update the GUI from another thread in C#?

Answer

private delegate void SetControlPropertyThreadSafeDelegate(
    Control control,
    string propertyName,
    object propertyValue);

public static void SetControlPropertyThreadSafe(
    Control control,
    string propertyName,
    object propertyValue)
{
  if (control.InvokeRequired)
  {
    control.Invoke(new SetControlPropertyThreadSafeDelegate               
    (SetControlPropertyThreadSafe),
    new object[] { control, propertyName, propertyValue });
  }
  else
  {
    control.GetType().InvokeMember(
        propertyName,
        BindingFlags.SetProperty,
        null,
        control,
        new object[] { propertyValue });
  }
}

All c sharp Questions

Ask your interview questions on c-sharp

Write Your comment or Questions if you want the answers on c-sharp from c-sharp Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---