Thread-safe invoke on NET CF

≡放荡痞女 提交于 2019-12-02 05:56:27

The Compact Framework does have Control.Invoke/BeginInvoke, although I believe it's limited to the EventHandler delegate (with any other delegate throwing an exception at execution time).

Assuming your actual instance of ISynchronizeInvoke is going to be a UI control, I'd just pass the reference as Control to whatever needs it. If you really want to use an interface, you could always create your own ISynchronizeInvoke interface, and then an implementation which just wraps Control.

Yes it is available in .NET CF, here is an extract from such a project:
SampleMethod() is called from another thread.

delegate void SimpleInvokeDelegate();
private void SampleMethod()
{
    if (InvokeRequired)
    {
        Invoke(new SimpleInvokeDelegate(SampleMethod));
    }
    else
    {
       // Update UI elements here.
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!