CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 25

Threaded View

  1. #1
    Join Date
    Aug 2006
    Posts
    515

    Eliminate PumpMessage()

    It is said that true Win32 should never use a function like PeekAndPump() below to make it responsive, instead threads should be used.
    Code:
    void PeekAndPump()
    {
        MSG msg;
        while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE)) 
        {
            AfxGetThread()->PumpMessage();
        }
    }
    Following the principal, I am loading a large file in a worker thread and posting its data to the main thread. It is working beautifully but because the worker thread is busy in continuous reading loop, the main window still doesn't get a chance to update data and is not as responsive. My first thought was that it can still use PeekAndPump()!? but I added a Sleep(5) to the loop in worker thread and the GUI is much smoother now but the delay also adds to file loading as well with each iteration in the loop. I am going to try introducing delay after 50 iterations now instead of each one but am I am on the right track? I want to the main GUI to be very responsive and not waste much time with file loading as well. PeekAndPump() is out right? Is delay function the only way?
    Last edited by zspirit; February 19th, 2010 at 05:10 PM.

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