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. What the!

What the!

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structures
5 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.
  • W Offline
    W Offline
    wilche
    wrote on last edited by
    #1

    Help! PostThreadMessage function fails without any apparent reason. The Message Queue is present. The Thread is present. GetLastError returns that "the operation is successful" BUT the message HAS NOT BEEN POSTED in the queue!!! Much appreciated if someone could help me with this problem Cheers, wilche :)

    A 1 Reply Last reply
    0
    • W wilche

      Help! PostThreadMessage function fails without any apparent reason. The Message Queue is present. The Thread is present. GetLastError returns that "the operation is successful" BUT the message HAS NOT BEEN POSTED in the queue!!! Much appreciated if someone could help me with this problem Cheers, wilche :)

      A Offline
      A Offline
      Alexandru Savescu
      wrote on last edited by
      #2

      This may sound silly, but did you try to but a breakpoint in the message handler to see it it gets there? Show us some more code, may we can tell what's wrong! Best regards, Alexandru Savescu

      W 1 Reply Last reply
      0
      • A Alexandru Savescu

        This may sound silly, but did you try to but a breakpoint in the message handler to see it it gets there? Show us some more code, may we can tell what's wrong! Best regards, Alexandru Savescu

        W Offline
        W Offline
        wilche
        wrote on last edited by
        #3

        Actually thanks for the reply but I think I may have found the problem. I added a Sleep function to force the thread to give up some CPU resources, then it works fine. I do this whenever the PostThreadMessage fails. So I wait and then resend. However, this seems to defeat the purpose of threads. I have two versions of the same application running, the difference is that one version pass its work using UI thread, while the other uses the main thread to do all its work. Currently it seems that the version using the UI thread is taking slightly longer than the other version because of this sleep function. It seems that the application is being seriously overloaded by the amount of messages it receives, causing it to resend lots of messages, making it sleep for long times! Furthermore it has taken me a lot more effort in getting this threaded version to work than the other version. So maybe threading is not always the best solution to improve performance? Kind regards, wilche

        M 1 Reply Last reply
        0
        • W wilche

          Actually thanks for the reply but I think I may have found the problem. I added a Sleep function to force the thread to give up some CPU resources, then it works fine. I do this whenever the PostThreadMessage fails. So I wait and then resend. However, this seems to defeat the purpose of threads. I have two versions of the same application running, the difference is that one version pass its work using UI thread, while the other uses the main thread to do all its work. Currently it seems that the version using the UI thread is taking slightly longer than the other version because of this sleep function. It seems that the application is being seriously overloaded by the amount of messages it receives, causing it to resend lots of messages, making it sleep for long times! Furthermore it has taken me a lot more effort in getting this threaded version to work than the other version. So maybe threading is not always the best solution to improve performance? Kind regards, wilche

          M Offline
          M Offline
          Mike Nordell
          wrote on last edited by
          #4

          wilche wrote: So maybe threading is not always the best solution to improve performance? There is no silver bullet. No, threading isn't always the best way to improve performance, though many (many many) applications could gain quite a bit of responsiveness and performance if they used threading in the right places, for the right reasons and in the right way.

          T 1 Reply Last reply
          0
          • M Mike Nordell

            wilche wrote: So maybe threading is not always the best solution to improve performance? There is no silver bullet. No, threading isn't always the best way to improve performance, though many (many many) applications could gain quite a bit of responsiveness and performance if they used threading in the right places, for the right reasons and in the right way.

            T Offline
            T Offline
            Tim Smith
            wrote on last edited by
            #5

            applications could gain quite a bit of responsiveness and performance if they used threading in the right places, for the right reasons and in the right way. This is so true. All too often I see people use threads and then fill the code with sync points (elements of the code where one thread must wait or sync with the other). Perfect threading has no sync points. Realistic threading has a few. Poor threading has the thread constantly syncing. When that happens, what is the real point. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?

            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