-
June 16th, 2012, 12:40 PM
#16
Re: PeekMessage
Originally Posted by ABM
It is my code which works fine on my work computer but not on my release version of the program.
Typical multithread issues.
As MikeAThon and myself have mentioned, whoever wrote the original code was not versed in proper usage of multiple threads and synchronization objects such as mutex, semaphore, critical section, etc.
If that person was versed in such topics, there wouldn't be the hack written using PeekMessage() and Sleep(). Once I see that, and the program is supposed to be multithreaded, it gives the impression that the code was written by someone who knows only about single-treaded programs and have no experience writing multi-threaded programs, therefore the hack that just happens to work on their computer.
Writing multithreaded programs takes experience in writing multi-threaded programs. This means knowing what the synchronization objects are (again, mutex, critical section, semaphore), how to use them, when to use them, and how to debug MT apps that do not behave correctly. You can have 20 years experience writing single-thread programs -- if you don't have experience writing MT programs, you wind up with a mess.
Regards,
Paul McKenzie
-
June 16th, 2012, 12:43 PM
#17
Re: PeekMessage
Originally Posted by ABM
Paul,
I fixed it. I was just trying to solve quickly that's why I was posted on this forum.
And how did you fix this problem?
Regards,
Paul McKenzie
-
June 18th, 2012, 09:59 AM
#18
Re: PeekMessage
Paul,
I still don't know the exact reason for doing that. But that's what I did
1. I had 3 timers which I had in my program which was just running not doing anything. I probably create sometime and never used it. My Bad.
2. I removed the Sleep. As I believe we use Mutex, Semaphore etc for thread synchronization as you'll mentioned in your previous posts.
3. I had two dialogs running in the Tab at the same time. Both of them have their own timers. So I change the PeekMessage to this
while(PeekMessage(&m,this->GetSafeHwnd(),WM_TIMER,WM_TIMER,PM_REMOVE))
{
KillTimer(m.wParam);
Sleep(1);
}
This about it. I am not still convince though that I need to use PeekMessage. If I make sure that every timer I set and I kill it later. Do I still need to use PeekMessage?
Regards,
ABM
-
June 18th, 2012, 10:14 AM
#19
Re: PeekMessage
I said way back, just KillTimer by itself will kill the timer. I don't see any need to the PeekMessage or sleep calls if all you're trying to do is kill timers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|