Thread-safe invoke on NET CF

前端 未结 2 1468
感动是毒
感动是毒 2021-01-25 10:40

I have a background thread running that fires events, but how can I ensure a thread safe invocation of these events using NET CF?

I would use ISyncronizeInvoke on the N

2条回答
  •  不思量自难忘°
    2021-01-25 11:27

    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.
        }
    }
    

提交回复
热议问题