MethodInvoker vs Action for Control.BeginInvoke

后端 未结 7 935
走了就别回头了
走了就别回头了 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:53

    It is a matter of preference in most cases, unless you intend to reuse the DoSomething() method. Also the anonymous functions will place your scoped variables on the heap, might make it a more expensive function.

提交回复
热议问题