[英]'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.