How can I make AllocateHwnd threadsafe?

后端 未结 3 1217
情话喂你
情话喂你 2020-12-01 05:59

VCL components are designed to be used solely from the main thread of an application. For visual components this never presents me with any difficulties. However, I would so

3条回答
  •  离开以前
    2020-12-01 06:25

    Don't use TTimer in a thread, it will never be safe. Have the thread either:

    1) use SetTimer() with a manual message loop. You don't need an HWND if you use a callback function, but you do still have to dispatch messages.

    2) use CreateWaitableTimer() and then call WaitForSingleObject() in a loop until the timer is signalled.

    3) use timeSetEvent(), which is a multi-threaded timer. Just be careful because its callback is called in its own thread so make sure your callback function is thread-safe, and there are restrictions to what you are allowed to call inside that thread. Best to have it set a signal that your real thread waits on an then does its work outside of the timer.

提交回复
热议问题