我的代码在不同于 UI 的线程中运行,它必须创建一个控件(Windows 窗体)。但是,我没有从 UI 中引用任何控件(这样,我可以使用myControl.Invoke( methodThatAddsControlToUI )
)。有没有办法在 .net紧凑框架中做到这一点?
如果可能的话,我会对不使用对其他控件的引用的解决方案感兴趣(例如,跟踪所有创建的表单不是一个好的解决方法,因为我的代码将在库中)。在完整的框架版本中,有该Application.OpenForms
属性,但这不会在 CF 中退出。
编辑:
这样做的主要目的是在 UI 线程上调用一个方法:
class Worker
{
public MyMethod()
{
// I need to call a method on the UI (this code doesn't run in the UI thread),
// but I don't have any field in this object holding an UI control
// value. So, I can't write myControlField.Invoke(...),
// but I still need to call a method on the UI thread
}
}
有什么建议么?