I'm doing simple GUI updates on a timer. Which method is better to use if i am updating a single control? MethodInvoker like this:
this.Invoke((MethodInvoker)delegate
{
  systemMode.Text = systemMode.ToString();
});
or create a control invoke like this:
public void UpdateSystemMode()
{
    if (systemMode.InvokeRequired)
    {
         UpdateSystemMode.Invoke(new
             UpdateSystemModeDelegate(UpdateSystemMode));
    }
    else
    {
        systemMode.UpdateSystemMode();
    }  
}
Obviously, the method invoker has less code up front, but which one is best practice?
UpdateSystemMode.Invoke(new UpdateSystemModeDelegate(UpdateSystemMode)); 
and
this.Invoke((MethodInvoker)delegate
{
  systemMode.Text = systemMode.ToString();
});
is absolutely same as well as
this.Invoke((Action)(()=> systemMode.Text = systemMode.ToString()));
right way:
public void UpdateSystemMode()
{
    if (this.InvokeRequired)
         this.BeginInvoke((Action)UpdateSystemMode);
    else
        systemMode.UpdateSystemMode(); 
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With