CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: PeekMessage

  1. #16
    Join Date
    Apr 1999
    Posts
    27,449

    Re: PeekMessage

    Quote Originally Posted by ABM View Post
    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

  2. #17
    Join Date
    Apr 1999
    Posts
    27,449

    Re: PeekMessage

    Quote Originally Posted by ABM View Post
    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

  3. #18
    Join Date
    Jun 2010
    Posts
    136

    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

  4. #19
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured