<bdo id='PMjUR'></bdo><ul id='PMjUR'></ul>

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

      <legend id='PMjUR'><style id='PMjUR'><dir id='PMjUR'><q id='PMjUR'></q></dir></style></legend>
      <tfoot id='PMjUR'></tfoot>

      不管 InvokeRequired 调用 Invoke 有什么问题?

      What#39;s wrong with calling Invoke, regardless of InvokeRequired?(不管 InvokeRequired 调用 Invoke 有什么问题?)

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

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

              <tbody id='fTfxJ'></tbody>
              <tfoot id='fTfxJ'></tfoot>

            • <legend id='fTfxJ'><style id='fTfxJ'><dir id='fTfxJ'><q id='fTfxJ'></q></dir></style></legend>
                本文介绍了不管 InvokeRequired 调用 Invoke 有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我已经看到了对 GUI 控件进行跨线程访问的常见设置,如下所述:最短的写法对 Windows 窗体控件的线程安全访问方法

                I've seen the common setup for cross threading access to a GUI control, such as discussed here: Shortest way to write a thread-safe access method to a windows forms control

                我发现的所有网络点击都描述了类似的事情.

                All the web hits I found describe a similar thing.

                但是,为什么我们需要检查 InvokeRequired?我们不能直接调用 Invoke 吗?

                However, why do we need to check InvokeRequired? Can't we just call Invoke directly?

                我假设答案是否定的,所以我真正的问题是为什么"?

                I assume the answer is no, so my real question is 'why'?

                推荐答案

                从非 UI 线程我们无法触摸 UI - 可能会发生非常糟糕的事情,因为控件具有线程关联性.因此,我们必须(至少)从非 UI 线程调用 InvokeBeginInvoke.

                From non-UI threads we can't touch the UI - very bad things can happen, since controls have thread affinity. So from a non-UI thread we must (at a minumum) call Invoke or BeginInvoke.

                然而,对于 UI 线程 - 我们想要调用 Invoke 很多时间;问题是,如果您已经在 UI 线程上,它仍然有向表单的泵发送消息并进行处理的不必要开销.

                For UI-threads, however - we don't want to call Invoke lots of time; the issue is that if you are already on the UI thread, it still has the unnecessary overhead of sending a message to the form's pump and processing it.

                实际上,在您知道的大多数线程代码中,您希望在 -UI 线程上调用特定方法,因此在这些情况下,不需要额外的开销:只需调用 Invoke.

                In reality, in most threading code you know you expect a specific method to be called on a non-UI thread, so in those cases, there is no additional overhead: just call Invoke.

                这篇关于不管 InvokeRequired 调用 Invoke 有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)
                <legend id='R2DbD'><style id='R2DbD'><dir id='R2DbD'><q id='R2DbD'></q></dir></style></legend>

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

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

                            <tbody id='R2DbD'></tbody>
                          <tfoot id='R2DbD'></tfoot>