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. Application freeze

Application freeze

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
9 Posts 4 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.
  • S Offline
    S Offline
    susanne1
    wrote on last edited by
    #1

    Hallo, i have the following function in SDI-application: void CMyClass::Myfunction() { CString strOutput; LPMSG *pmsg = NULL; for(int i = 0; i < 3000; i++) { ::PeekMessage(NULL,NULL,0,0,PM_NOYIELD | PM_REMOVE); strOutput.Format ("%d",i); m_ptrOutput->SetWindowTextA (strOutput); } } as you see the for-loop goes 3000 times and should print the value of i, what happens when this function starts is the appliction FREEZ. I do not have any idea why this happens and how to solve this problem.Please help.

    _ R M 3 Replies Last reply
    0
    • S susanne1

      Hallo, i have the following function in SDI-application: void CMyClass::Myfunction() { CString strOutput; LPMSG *pmsg = NULL; for(int i = 0; i < 3000; i++) { ::PeekMessage(NULL,NULL,0,0,PM_NOYIELD | PM_REMOVE); strOutput.Format ("%d",i); m_ptrOutput->SetWindowTextA (strOutput); } } as you see the for-loop goes 3000 times and should print the value of i, what happens when this function starts is the appliction FREEZ. I do not have any idea why this happens and how to solve this problem.Please help.

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      What is that magic number 3000? Why do you want to loop 3000 times?

      «_Superman_» I love work. It gives me something to do between weekends.

      S 1 Reply Last reply
      0
      • _ _Superman_

        What is that magic number 3000? Why do you want to loop 3000 times?

        «_Superman_» I love work. It gives me something to do between weekends.

        S Offline
        S Offline
        susanne1
        wrote on last edited by
        #3

        loop 3000 to get the rows from a database : select * from DB;

        1 Reply Last reply
        0
        • S susanne1

          Hallo, i have the following function in SDI-application: void CMyClass::Myfunction() { CString strOutput; LPMSG *pmsg = NULL; for(int i = 0; i < 3000; i++) { ::PeekMessage(NULL,NULL,0,0,PM_NOYIELD | PM_REMOVE); strOutput.Format ("%d",i); m_ptrOutput->SetWindowTextA (strOutput); } } as you see the for-loop goes 3000 times and should print the value of i, what happens when this function starts is the appliction FREEZ. I do not have any idea why this happens and how to solve this problem.Please help.

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          susanne1 wrote:

          LPMSG *pmsg = NULL;

          What is the purpose of this pointer variable? You aren't using it anywhere in your code. Not to mention LPMSG is already a pointer to a MSG structure. :|

          void Func()
          {
          CString szOutput;
          MSG msg;

          for(int i=0; i<3000; i++)
          {
          PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); //You must use PM_NOREMOVE if you want the message to remain in the queue.
          szOutput.Format(_T("%d"), i);
          OutputDebugString(szOutput);
          }

          Why would you do something like this? Are you trying to understand how PeekMessage works or ... ?

          It is a crappy thing, but it's life -^ Carlo Pallini

          S 1 Reply Last reply
          0
          • R Rajesh R Subramanian

            susanne1 wrote:

            LPMSG *pmsg = NULL;

            What is the purpose of this pointer variable? You aren't using it anywhere in your code. Not to mention LPMSG is already a pointer to a MSG structure. :|

            void Func()
            {
            CString szOutput;
            MSG msg;

            for(int i=0; i<3000; i++)
            {
            PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); //You must use PM_NOREMOVE if you want the message to remain in the queue.
            szOutput.Format(_T("%d"), i);
            OutputDebugString(szOutput);
            }

            Why would you do something like this? Are you trying to understand how PeekMessage works or ... ?

            It is a crappy thing, but it's life -^ Carlo Pallini

            S Offline
            S Offline
            susanne1
            wrote on last edited by
            #5

            i must do it because i have over 40000 rows in the database(wher can i find a tutorial that explain how peekmessgae works??) do not i need to intialize the msg before i use it? i used the PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);in the loop that retrives the rows but nothing changed positively??

            R 1 Reply Last reply
            0
            • S susanne1

              i must do it because i have over 40000 rows in the database(wher can i find a tutorial that explain how peekmessgae works??) do not i need to intialize the msg before i use it? i used the PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);in the loop that retrives the rows but nothing changed positively??

              R Offline
              R Offline
              Rajesh R Subramanian
              wrote on last edited by
              #6

              You actually are in need of a good book. For book recommendations, see here[^]. Here[^] is a good tutorial on threading. But, that can hardly help you if you don't get a good grip of the basics at first.

              It is a crappy thing, but it's life -^ Carlo Pallini

              S 1 Reply Last reply
              0
              • R Rajesh R Subramanian

                You actually are in need of a good book. For book recommendations, see here[^]. Here[^] is a good tutorial on threading. But, that can hardly help you if you don't get a good grip of the basics at first.

                It is a crappy thing, but it's life -^ Carlo Pallini

                S Offline
                S Offline
                susanne1
                wrote on last edited by
                #7

                okay thanks but for now how can i solve this problem?

                R 1 Reply Last reply
                0
                • S susanne1

                  okay thanks but for now how can i solve this problem?

                  R Offline
                  R Offline
                  Rajesh R Subramanian
                  wrote on last edited by
                  #8

                  You cannot solve this problem until you understand the basics. If I start to tell why you should not use PeekMessage there, I'll have to explain what a worker thread is, thread synchronization, applying everything together in your program, etc., Too much of stuff to be discussed in a thread like this. You are desperately in need of a book and go buy one or two. Your program can wait until you're good enough to solve it. And no pal, I do not feel like providing you a quick-fix. Sorry about that.

                  It is a crappy thing, but it's life -^ Carlo Pallini

                  1 Reply Last reply
                  0
                  • S susanne1

                    Hallo, i have the following function in SDI-application: void CMyClass::Myfunction() { CString strOutput; LPMSG *pmsg = NULL; for(int i = 0; i < 3000; i++) { ::PeekMessage(NULL,NULL,0,0,PM_NOYIELD | PM_REMOVE); strOutput.Format ("%d",i); m_ptrOutput->SetWindowTextA (strOutput); } } as you see the for-loop goes 3000 times and should print the value of i, what happens when this function starts is the appliction FREEZ. I do not have any idea why this happens and how to solve this problem.Please help.

                    M Offline
                    M Offline
                    Michael Tharigen
                    wrote on last edited by
                    #9

                    You should sometimes (e.g. after reading of 100 data) call a function like this. If you remove the message from the queue, you should dispatch the message. You can call PeekMessage with other filters too (e.g. for a special window or other messages). But the last call should not use any filters! void PeekMessages() { MSG msg; // check for paint-messages ... while ( PeekMessage(&msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE) ) { // ... and dispatch these TranslateMessage(&msg); DispatchMessage(&msg); } // only to prevent ghost-window on vista! // we dont use the result and let the message // in the queue (PM_NOREMOVE) PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); }

                    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