我有一个不同于UI的线程运行的代码,它必须创建一个控件(windows窗体)。但是,我没有提及UI的任何控件(这样,我可以使用myControl.Invoke(methodThatAddsControlToUI)
)。有没有办法做到这一点.net 紧凑框架?如果可能的话,我会对不使用其他控件引用的解决方案感兴趣(跟踪所有创建的表单,例如,将不是一个很好的解决方法,因为我的代码将位于库中)。在完整的框架版本中,有Application.OpenForms
属性,但这不会在CF中退出。如何从其他线程(.net精简框架)正确创建控件,而不参考其他控件?
编辑:
这样做的主要目的是呼吁在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
}
}
有什么建议?
我可能失去了一些东西,但你有什么打算,如果你有没有其他的控制来分配其与新的控制做至? – 2012-07-19 15:30:15
我想用它来调用UI上的方法,有点像newControl.Invoke(myMethod) – 2012-07-19 15:32:46
你可以给我们一些代码示例吗?我很难理解你想要做什么!对于那个很抱歉。 – 2012-07-19 15:37:58