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