Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    currently Lisbone, Portugal
    Posts
    154
    Rep Power
    12

    Post Program window does not refresh. What is wrong ???


    :) Welcome everyone,
    since I had a busy night, I came across some strange problem.
    I have a program which does a looooot of calculations. Lots means a couple of hours. After five seconds, the program stops responding and becomes a resident in the system, but works correctly in the background, since the generated output files are correct and keep on growing.
    The problem is that I want to show user that the program is actually working OK, and I cannot do it when the program window does not respond. Is there any way of forcing refresh on the window? I tried Invalidate() but does not seem to have too much effect on it. :confused:
    Can anyone at least try to help with that? It is not very important but I would liek to know that.
    Thanks for posts
    Marek
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    I'm assuming you're using mfc or win32. Either way, ui updates only occur when your program enters idle states, which won't happen if you're program is churning away calculations for hours without end.

    One solution is to break up the calculations, restarting them on consecutive idle messages. Another is to begin a slave thread, which runs independent of the ui thread.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    currently Lisbone, Portugal
    Posts
    154
    Rep Power
    12
    So what You are saying is there is no way to do that without breaking up the flow of calculations. The problem is that there is no way of breaking them up. If I do that, I would have to store a lot of intermediate results in the memory, much too much to be honest.
    Could You give some details about this slave thread? I have heard nothing about that so far.
    Thanks
    Marek
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,182
    Rep Power
    2222
    Originally posted by marek_haj

    Could You give some details about this slave thread? I have heard nothing about that so far.
    It's called Multithreaded Programming. Look up CWinThread under MFC or pthreads (POSIX threads) under Linux. Most of the concepts are the same between the two, but the actual function names and syntax are different.

    We will need to know which OS and development system you are using to be able to be more specific.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    currently Lisbone, Portugal
    Posts
    154
    Rep Power
    12
    Hello
    when it comes to the operation system it is win2000 for now. I have been obliged to use it since the end user (that is my university professor has it installed).
    If thsi is no problem, just let me know what kinda of function to look for, I think I will be able to handle this once I know what to look for specifically.
    Thanks
    Best greets
    Marek
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    CWinThread is the mfc class you're looking for, it encapsulates the calls to win32 api to create threads. Also lookup AfxBeginThread, which creates a thread and begins it's execution, and AfxEndThread, which can be used from within the thread to end execution.

    I can't offer much advice though, I've never written a 'real' multithreaded program, just excercies.
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    currently Lisbone, Portugal
    Posts
    154
    Rep Power
    12
    Nevertheless, thanks a lot. Now I know what to look for. It is going to be much easier.
    Best greets
    MArek
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    I tried Invalidate() but does not seem to have too much effect on it.
    Isnīt there an ::Update() method? If not, try sending WM_PAINT to the window regularly...
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    currently Lisbone, Portugal
    Posts
    154
    Rep Power
    12
    Well, I am going to test it out in a few minutes, if it works, it is going to be muuuuch easier than creating threads, I began to read about that and honestly - there has to be easier way to do that. :D
    Thanks for the post
    Best greets
    MArek :)
  18. #10
  19. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    currently Lisbone, Portugal
    Posts
    154
    Rep Power
    12
    wel I tried to find the Update() method but in vain. There is no such method avaliable or I caanot find it. Either way, perhaps You have some more details on it ? At least where I could find it?
    Thanks for posts
    Best greets
    MArek
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    272
    Rep Power
    19
    Try UpdateWindow.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    UpdateWindow is a member of CWnd and CWindow.

    I doubt sending a WM_PAINT message will work. If I remember the Windows message queue model correctly, the queue is read on idle states, which of course won't happen until you're large calculation process returns.

    Similarly, all UpdateWindow does is dump a WM_PAINT message into the queue, so it won't be any different than the sending a message.

    Let us know though, if it works.
    Last edited by MJEggertson; April 2nd, 2003 at 01:10 PM.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    Found this method though: CWnd::RedrawWindow.

    It seems to force an immediate redraw of a given area. That is, it doesn't send WM_PAINT messages, it does an actual draw operation. May work.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    The message queue will only be read when the app goes idle?

    How can a SendMessage() return values then? It has to wait for a message to be processed -> the calling thread will be stopped and the program will be idle. This description could be wrong, but the effect is iirc the same.
    AFAIK PostMessage() is the function that will not block the calling thread.

    Wrong?
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    Right, my bad. I was thinking PostMessage. Heh...phew....time for lunch.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo