开发者

Efficient implementation of a threaded console window

I have a Win32 application that consists of two components: A main window that acts as the app's interface and a secondary modeless dialog that functions as a console. The applicati开发者_StackOverflow社区on generates copious amounts of debug text during certain (regular) operations.

Having to update the console's edit control during every debug print call is rather expensive given my constraints. My intention is to create a critical section synchronized message queue that is dumped periodically by a worker thread. I'd appreciate any suggestions on how such an implementation can be coded.


In the worker thread, lock the CS and add to a shared data structure. In the GUI thread, set a timer and in the WM_TIMER message handler, lock the CS, remove from the shared data structure, and append to the edit control.


Try sleeping the message pump on the edit control window, instead of running a new thread.


Just take care of this recurrent problem relating to multithreading and GUI:

Never access to Gui elements from another thread, you have to post message to the window , so the code will be executed in the main thread when changing something in the GUI.


I tried using a timer in the main thread and it worked well enough for me. My thanks to the posters!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜