Executing a method on ui thread due to an event on background thread

后端 未结 3 1898
小蘑菇
小蘑菇 2020-12-10 08:33

I\'ve got a background thread that is polling a server. When there\'s data, I want to handle the data on the UI thread. If I store the hwnd of the main window.

3条回答
  •  旧巷少年郎
    2020-12-10 08:56

    One thing that you could do - use an inter-thread signalling object perhaps as simple as a boolean flag. When data appears on the server polling thread, you can signal the flag. You could check for this flag in the message loop of your UI thread. Alternatively, you could just send the UI thread a custom window message.

    Now that I re-read your question - since you can't change the UI code, this approach wouldn't work. You could use the WIN32 API to add your own custom message hook function to fix this problem.

提交回复
热议问题