简体   繁体   English

调用了“ Invoke”和“ BeginInvoke”,但从未解决

[英]'Invoke' and 'BeginInvoke' are called but never resolved

I am taking care of the GUI thread of a piece of software. 我正在照顾一个软件的GUI线程。 I have to display inside a GridView data that needs to be constantly polled from the underlying APIs. 我必须在GridView中显示需要不断从底层API轮询的数据。 I created a method called Sync() which updates the data, and I tried to make it thread safe by using BeginInvoke and/or Invoke . 我创建了一个称为Sync()的方法来更新数据,并尝试通过使用BeginInvoke和/或Invoke使它成为线程安全的。 The Sync method is called by a timer every five seconds or so. 计时器每五秒钟左右调用一次Sync方法。

The body of Sync is never called, as for some reason it seems that my request is never pulled from the message pump. 永远不会调用Sync的主体,因为某种原因,似乎从未从消息泵中拉出我的请求。 The code: 编码:

 public void Sync()
    {
        if (this.InvokeRequired)
        {
            logger.Debug("Begin Invoke of Sync operation");
            this.Invoke(new SyncDelegate(Sync));
            logger.Debug("End Invoke of Sync operation");
        }
        else
        {
            logger.Debug("Inside body");
        }

    }

The log looks like: 日志如下:

10:00:00 Begin Invoke of Sync operation
... other stuff ...
10:00:05 Begin Invoke of Sync operation
... other stuff ...
10:00:10 Begin Invoke of Sync operation

The other messages are never printed. 其他消息从不打印。

The same for BeginInvoke . 对于BeginInvoke "End Invoke ... " is printed but "inside body ..." is never printed. “ End Invoke ...”被打印,但是“ inside body ...”从不被打印。

I'm running on top of Unity3D and MonoDevelop (if this changes anything). 我正在Unity3D和MonoDevelop之上运行(如果这有任何改变)。

Solved. 解决了。 Apparently I was creating the Windows Form outside of the Application.Run command. 显然我是在Application.Run命令之外创建Windows窗体。 For some reason instantiating the Form inside the Application.Run comand did the trick 由于某种原因,实例化Application.Run中的Form并完成了窍门

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我从不使用 Invoke 或 BeginInvoke 时,无法调用 Invoke 或 BeginInvoke 错误 - Invoke or BeginInvoke cannot be called Error when I never use Invoke or BeginInvoke 调用或BeginInvoke不能称为错误 - Invoke or BeginInvoke cannot be called Error “在标签上”之前,无法在控件上调用“调用”或“BeginInvoke” - “Invoke or BeginInvoke cannot be called on a control until” on a Label Invoke和BeginInvoke - Invoke and BeginInvoke 无法在控件上调用Invoke或BeginInvoke…即使使用CreateControl() - Invoke or BeginInvoke cannot be called on a control… even using CreateControl() 在C#中调用BeginInvoke / Invoke时如何获取返回值 - How to get return value when BeginInvoke/Invoke is called in C# 无法在尚未创建的控件上调用Invoke或begininvoke - Invoke or begininvoke cannot be called on a control which is not yet created dataGridView_CellContentClick:不能在控件上调用Invoke或BeginInvoke - dataGridView_CellContentClick: Invoke or BeginInvoke cannot be called on a control ISynchronizeInvoke 调用与 BeginInvoke - ISynchronizeInvoke Invoke vs BeginInvoke 为什么在控件上调用Dispose()之后,控件的BeginInvoke()目标委托永远不会发生? - Why does a Control's BeginInvoke() target delegate never occur after Dispose() is called on the Control?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM