Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Waiting...

Waiting...

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abhijeet Pathak
    wrote on last edited by
    #1

    Hi, Sleep() function makes application sleep for specified time, but it blocks the thread from processing anything. How can i make application sleep for some time but still process the messages? (e.g. equivalent to DoEvents in Visual Basic 6) ----- Don't look back... See your stomach...

    B H 2 Replies Last reply
    0
    • A Abhijeet Pathak

      Hi, Sleep() function makes application sleep for specified time, but it blocks the thread from processing anything. How can i make application sleep for some time but still process the messages? (e.g. equivalent to DoEvents in Visual Basic 6) ----- Don't look back... See your stomach...

      B Offline
      B Offline
      baerten
      wrote on last edited by
      #2

      The sleep() lets sleep the thread where it's inside. If you let sleep the WinThread, so all the windows will sleep too. You need to use workerthreads, there in you can let sleep the threads as long as you want and the windows will not be affected ... Good luck

      1 Reply Last reply
      0
      • A Abhijeet Pathak

        Hi, Sleep() function makes application sleep for specified time, but it blocks the thread from processing anything. How can i make application sleep for some time but still process the messages? (e.g. equivalent to DoEvents in Visual Basic 6) ----- Don't look back... See your stomach...

        H Offline
        H Offline
        Hans Dietrich
        wrote on last edited by
        #3

        This is for UI thread:

        void Delay(DWORD dwMsecs, BOOL bBlocking)
        {
        static BOOL bInDelay = FALSE;

        if (bInDelay)
            return;
        bInDelay = TRUE;
        
        DWORD dwStrtmsecs, dwCurmsecs;
        MSG msg;
        
        dwStrtmsecs = dwCurmsecs = ::GetCurrentTime();
        
        do 
        {
            if (!bBlocking)
            {
                if (::PeekMessage(&msg, NULL, 0, 0, PM\_REMOVE)) 
                {
                    if (msg.message == WM\_QUIT)
                    {
                        ::PostMessage(NULL, WM\_QUIT, 0, 0L);
                        break;
                    }
                    else
                    {
                        ::TranslateMessage(&msg);
                        ::DispatchMessage(&msg);
                    }
                }
            }
        
            dwCurmsecs = ::GetCurrentTime();
        
            // check for timer overflow condition
            if (dwCurmsecs < dwStrtmsecs)
                dwStrtmsecs = dwCurmsecs;
        
        } while ((dwCurmsecs  < (dwMsecs + dwStrtmsecs)));
        
        bInDelay = FALSE;
        

        }

        Best wishes, Hans


        [CodeProject Forum Guidelines] [How To Ask A Question] [My Articles]

        A 1 Reply Last reply
        0
        • H Hans Dietrich

          This is for UI thread:

          void Delay(DWORD dwMsecs, BOOL bBlocking)
          {
          static BOOL bInDelay = FALSE;

          if (bInDelay)
              return;
          bInDelay = TRUE;
          
          DWORD dwStrtmsecs, dwCurmsecs;
          MSG msg;
          
          dwStrtmsecs = dwCurmsecs = ::GetCurrentTime();
          
          do 
          {
              if (!bBlocking)
              {
                  if (::PeekMessage(&msg, NULL, 0, 0, PM\_REMOVE)) 
                  {
                      if (msg.message == WM\_QUIT)
                      {
                          ::PostMessage(NULL, WM\_QUIT, 0, 0L);
                          break;
                      }
                      else
                      {
                          ::TranslateMessage(&msg);
                          ::DispatchMessage(&msg);
                      }
                  }
              }
          
              dwCurmsecs = ::GetCurrentTime();
          
              // check for timer overflow condition
              if (dwCurmsecs < dwStrtmsecs)
                  dwStrtmsecs = dwCurmsecs;
          
          } while ((dwCurmsecs  < (dwMsecs + dwStrtmsecs)));
          
          bInDelay = FALSE;
          

          }

          Best wishes, Hans


          [CodeProject Forum Guidelines] [How To Ask A Question] [My Articles]

          A Offline
          A Offline
          Abhijeet Pathak
          wrote on last edited by
          #4

          Wow, thanks a lot... there's lot to learn out there, i guess... :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups