<i id='GfmqI'><tr id='GfmqI'><dt id='GfmqI'><q id='GfmqI'><span id='GfmqI'><b id='GfmqI'><form id='GfmqI'><ins id='GfmqI'></ins><ul id='GfmqI'></ul><sub id='GfmqI'></sub></form><legend id='GfmqI'></legend><bdo id='GfmqI'><pre id='GfmqI'><center id='GfmqI'></center></pre></bdo></b><th id='GfmqI'></th></span></q></dt></tr></i><div id='GfmqI'><tfoot id='GfmqI'></tfoot><dl id='GfmqI'><fieldset id='GfmqI'></fieldset></dl></div>
  • <tfoot id='GfmqI'></tfoot>
    • <bdo id='GfmqI'></bdo><ul id='GfmqI'></ul>
    <legend id='GfmqI'><style id='GfmqI'><dir id='GfmqI'><q id='GfmqI'></q></dir></style></legend>
    1. <small id='GfmqI'></small><noframes id='GfmqI'>

      1. Control.BeginInvoke 的 MethodInvoker 与 Action

        时间:2023-11-11

        <small id='16Khs'></small><noframes id='16Khs'>

      2. <i id='16Khs'><tr id='16Khs'><dt id='16Khs'><q id='16Khs'><span id='16Khs'><b id='16Khs'><form id='16Khs'><ins id='16Khs'></ins><ul id='16Khs'></ul><sub id='16Khs'></sub></form><legend id='16Khs'></legend><bdo id='16Khs'><pre id='16Khs'><center id='16Khs'></center></pre></bdo></b><th id='16Khs'></th></span></q></dt></tr></i><div id='16Khs'><tfoot id='16Khs'></tfoot><dl id='16Khs'><fieldset id='16Khs'></fieldset></dl></div>
          <tbody id='16Khs'></tbody>
          <bdo id='16Khs'></bdo><ul id='16Khs'></ul>
        • <legend id='16Khs'><style id='16Khs'><dir id='16Khs'><q id='16Khs'></q></dir></style></legend>
          <tfoot id='16Khs'></tfoot>

                • 本文介绍了Control.BeginInvoke 的 MethodInvoker 与 Action的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  哪个更正确,为什么?

                  Control.BeginInvoke(new Action(DoSomething), null);
                  
                  private void DoSomething()
                  {
                      MessageBox.Show("What a great post");
                  }
                  

                  Control.BeginInvoke((MethodInvoker) delegate { 
                      MessageBox.Show("What a great post");
                  }); 
                  

                  我觉得我在做同样的事情,那么什么时候使用 MethodInvokerAction 比较合适,甚至是写一个 lambda 表达式?

                  I kinda feel like I am doing the same thing, so when is the right time to use MethodInvoker vs Action, or even writing a lambda expression?

                  我知道编写 lambda 与 Action 之间并没有太大区别,但 MethodInvoker 似乎是为特定目的而制作.它有什么不同吗?

                  I know that there isn't really much of a difference between writing a lambda vs Action, but MethodInvoker seems to be made for a specific purpose. Is it doing anything different?

                  推荐答案

                  两者都同样正确,但 Control.Invoke 声明:

                  Both are equally correct, but the documentation for Control.Invoke states that:

                  委托可以是EventHandler,在这种情况下是发送者参数将包含此控件,并且事件参数将包含EventArgs.Empty.委托人也可以是 MethodInvoker 的一个实例,或者任何其他无效的代表参数列表.一个电话EventHandler 或 MethodInvoker 委托会比打电话给另一个人更快代表的类型.

                  The delegate can be an instance of EventHandler, in which case the sender parameter will contain this control, and the event parameter will contain EventArgs.Empty. The delegate can also be an instance of MethodInvoker, or any other delegate that takes a void parameter list. A call to an EventHandler or MethodInvoker delegate will be faster than a call to another type of delegate.

                  所以 MethodInvoker 会是更有效的选择.

                  So MethodInvoker would be a more efficient choice.

                  这篇关于Control.BeginInvoke 的 MethodInvoker 与 Action的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 C# 中清除事件订阅? 下一篇:简单委托(委托)与多播委托

                  相关文章

                  <small id='DWBC1'></small><noframes id='DWBC1'>

                    <i id='DWBC1'><tr id='DWBC1'><dt id='DWBC1'><q id='DWBC1'><span id='DWBC1'><b id='DWBC1'><form id='DWBC1'><ins id='DWBC1'></ins><ul id='DWBC1'></ul><sub id='DWBC1'></sub></form><legend id='DWBC1'></legend><bdo id='DWBC1'><pre id='DWBC1'><center id='DWBC1'></center></pre></bdo></b><th id='DWBC1'></th></span></q></dt></tr></i><div id='DWBC1'><tfoot id='DWBC1'></tfoot><dl id='DWBC1'><fieldset id='DWBC1'></fieldset></dl></div>
                  1. <tfoot id='DWBC1'></tfoot><legend id='DWBC1'><style id='DWBC1'><dir id='DWBC1'><q id='DWBC1'></q></dir></style></legend>

                      • <bdo id='DWBC1'></bdo><ul id='DWBC1'></ul>