Can I start a timer inside a thread [modified]
-
I want to do a periodic checking of data inside a thread. Can i start Timer in a UI thread derived from CWinThread? -- modified at 1:50 Friday 27th April, 2007
"Timer" - what exactly you mean? If you mean CWnd::SetTimer/KillTimer pair, than you can do it only if there is a window in your UI thread and meantime it is logical to assign the timer to it. Do you have windows? Or only is message pump there?
-- ===== Arman
-
I want to do a periodic checking of data inside a thread. Can i start Timer in a UI thread derived from CWinThread? -- modified at 1:50 Friday 27th April, 2007
The short answer is "yes, you can". ;) From Arman's reply I guess you didn't think about a UI-thread and a CWinThread derived object from the start and you don't really need a UI-thread. I suggest you create an ordinary worker thread, see here[^] how to do it and avoid common pitfalls. Create a waitable timer with ::CreateWaitableTimer( NULL, FALSE, NULL )[^] inside your worker thread and wait on the timer handle with e.g.
::WaitForMultipleObjects(...)
. Start the timer with ::SetWaitableTimer(...)[^] and make it periodic.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown