In C#, wait on the mainthread while continuing to process UI updates? (.NET 2.0 CF)

前端 未结 10 2219
梦谈多话
梦谈多话 2020-12-18 11:49

I want to otherwise block code execution on the main thread while still allowing UI changes to be displayed.

I tried to come up with a simplified example version of

10条回答
  •  没有蜡笔的小新
    2020-12-18 12:18

    I went with something I haven't seen posted yet which is to use MessageQueues.

    • The MainThread blocks while waiting for the next message on a queue.
    • The background thread posts different types of messages to the MessageQueue.
    • Some of the message types signal the MainThread to update UI elements.
    • Of course, there is a message to tell the MainThread to stop blocking and waiting for messages.

    Seems over the top considering the windows message loop already exists somewhere, but it works.

提交回复
热议问题