MethodInvoker vs Action for Control.BeginInvoke

后端 未结 7 921
走了就别回头了
走了就别回头了 2020-11-28 22:33

Which is more correct and why?

Control.BeginInvoke(new Action(DoSomething), null);

private void DoSomething()
{
    MessageBox.Show(\"What a great post\");
         


        
7条回答
  •  渐次进展
    2020-11-28 22:55

    Don't forget to somehow check if control is available at the moment, to avoid errors at closing form.

    if(control.IsHandleCreated)
    control.BeginInvoke((MethodInvoker)(() => control.Text="check123"));
    

提交回复
热议问题