class derived from CWinThread

I have a class that i derived from CWinThread. I have a dialog box app that starts two threads (or more) when it starts. these threads execute some code that then wait a certain amount of time before it repeats the process. I am using the Sleep function to wait the certain amount of time.

What i would like to do is modifiy the code so that it works like this. the thread executes the code and then waits a certain amount of time. While it is waiting it can recieve messages. the message that it should be waiting to recieve would be execute code now. So it would work like this or something like it

thread starts
thread executes code
thread waits a set amount of time AND can accept messages
while it waits it can accept a message to execute code now
If no such message comes then it waits for the set amount of time then executes the code and then waits again.
While it waits it can accept the execute code command at any time BUT does not reset the timer. So it the timer is set for 5 minutes and the execute code message is recieve 5 seconds before the timer is up the code is executed and when the timer ends in 5 secs the code is executed again and the timer starts all over again

UNLESS the message to quit the thread is recieved. Any time this message is recieved then the thread shuts down and free up an memory it was using.

I'd suggest that you just set a TIMER in your thread for the interval you want to wait and then return to Windows. If any messages come in, they will get processed and then when your timer expires, you'll get that message as well.

I'm of the opinion that NO Windows application should ever use Sleep().

Then, the thread would recieve a MSG_THREADn message every five seconds, and would still recieve other messages. I don't know that this is the correct code - I'm not an experienced C++ programmer - but it could be a start.

I'd suggest that you just set a TIMER in your thread for the interval you want to wait and then return
to Windows. If any messages come in, they will get processed and then when your timer expires, you'll
get that message as well.

"it the timer is set for 5 minutes and the execute code message is recieve 5 seconds before the timer
is up the code is executed and when the timer ends in 5 secs the code is executed again and the timer
starts all over again"

What if the message is recieved just before the timer ends and before the code is executed the timer goes off ... Is the code executed for the message exec command and when it returns checks if the timeer's ended then executes the code and resets the timer.

How is ur thread recieving messages ? what kinda messages ..are they events or the windows messages (on which u can use peekmessage)

You could use waitforsingleobject with the timeout value set to timer and waiting on the message event in a while loop.
and can have the following ..
if timeout :executecode
if message : then
0 .note the current time : t0
1. execute code
2 timer = timer - (current time(t1) -t0)ms ;
if (timer <= 0) execute code and set timer to TIMEOUT.

0,1,2 are so that the time spent in executing command is also included in the TIMEOUT value.

if you are using window messaging then the method is different.
Please let us know.

As long as you stay in your loop you will not receive any messages from Windows. You must "return" and let Windows process the messages and dispatch them to your app.

Again, set a timer with SetTimer() and then return. When the timer expires, you'll get a WM_TIMER message. Either stop the timer with KillTimer or do whatever and return again. If any other messages come for your window, you'll receive them....

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Featured Post

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Introduction
This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …

C++ Properties
One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…

The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.