Click to See Complete Forum and Search --> : Loop executing one thread
sunny_sz
April 6th, 2006, 07:05 AM
Hello everbody :
I am doing my app , and I want to loop executing one thread , I know how to start a thread , but do not know how to loop executing one thread without using OnTimer() .
Say :
There is a thread for displaying current time in my edit box , now what i want is : when I click on one button to start thread and loop executing displaying current time(that's to say : always displaying update local time in my edit box) , once click on stop button , will stop thread and stop update current time .
Could anyone give me any code snippet ??
Thanks here beforehand .
philkr
April 6th, 2006, 07:14 AM
You could create a global variable bool bStop = false; and set it to true if you want to stop the thread.
Thread function could look like this:
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
while(!bStop)
{
UpdateTimer();
Sleep(1000); // Replace 1000 with the update interval
}
return 0;
}
sunny_sz
April 6th, 2006, 07:34 AM
Thanks for ur response first.
If there are two thread in my project , and I want the two thread to run synchro , and now how to realize that ?(without using OnTimer()).
Could you pls. help me out of that ?
Thank you once again !
philkr
April 6th, 2006, 07:39 AM
Now I don't understand what you mean. I thought you had your main thread (the one which always exists) and now wanted to create a new using CreateThread() for updating the timer. I gave you the code for its thread function.
Do you now want to create another thread? What should this thread be doing?
sunny_sz
April 6th, 2006, 07:59 AM
Sorry for not detailed description .
Provisionally , forsake the case above , assume that there are two threads in my another project , when I click on "Run" button to start the two threads(they are running synch.) Now what i want is how to make the two threadings run synch .
Could you pls. help me ?
Anyway , thank you very much !
kuphryn
April 6th, 2006, 11:39 AM
critical section
Kuphryn
sunny_sz
April 6th, 2006, 11:48 PM
Thanks for ur response , kuphryn .
But my knowledge on multithreading programming is very poor , could you pls. be in details ?
Thank you once again beforehand !
kuphryn
April 7th, 2006, 11:39 AM
Post your question.
Kuphryn
sunny_sz
April 10th, 2006, 10:26 PM
Say :
There are two threads in my project. now I want the two thread to run Synch and loop executing that .
Base on this , could you show me some code snippet or hints ?
Thanks.
kuphryn
April 11th, 2006, 12:18 AM
you first
Post your example. What is unclear?
Kuphryn
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.