MFC: accessing GUI from another thread?

前端 未结 2 929
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-18 15:13

So generally only the main thread should access the GUI in a MFC application.

However is that a law or just recommended? If I make sure, via critical sections, that

2条回答
  •  醉梦人生
    2020-12-18 15:35

    I used to think its almost forbidden to access GUI from a worker thread in MFC and is a recipe for disaster. But recently I learned this is not that hard rule if you know what you are doing, you can use worker threads to access GUI. In the Win32 Multithreaded Book the provides an example of a 'self animated control' which is completely drawn in a worker thread.

    If I remember correctly the author pretty much said the same thing you said, if you critical sections at the right places you can make accessing GUI thread safe. The reason MFC doesn't do it by itself is for performance reasons.

提交回复
热议问题