当前上下文中不存在 Control.Invoke [英] Control.Invoke does not exist in the current context
问题描述
错误:当前上下文中不存在名称调用"
Error: The name 'Invoke' does not exist in the current context
我正在处理的类已经有一个基类,所以我不能让它实现 Windows.Forms.Control 之类的东西.
The class I am working on already has a base class so I can't have it implement something like Windows.Forms.Control.
我看了文章这里但我不想实现另一个接口,也不知道是什么我会加入方法.
I looked at article here but I don't want to implement another interface, and don't know what I would put in the methods.
这是一个相当低级的 C# 适配器程序,因此它无法访问大多数 UI 内容会访问的库
This is a fairly low level C# adaptor program so it doesn't have access to the libraries most UI stuff would
编辑我正在尝试做这样的事情
EDIT I'm trying to do something like this
// On thread X
Invoke((m_delegate)delegate(){
// Do something on main thread
});
推荐答案
我最终使用了 Action 委托带有匿名方法,将对象传递给正确的线程,然后执行.效果很好,我觉得这段代码很性感.
I ended up using Action delegate with an anonymous method, that is passed in an object to the right thread, and then executed. Works great and I find this code pretty sexy.
这篇关于当前上下文中不存在 Control.Invoke的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!