April 1st, 2003, 02:15 AM
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
April 1st, 2003, 02:38 AM
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.
April 1st, 2003, 06:15 AM
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.
April 1st, 2003, 09:40 AM
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.
April 1st, 2003, 10:39 AM
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.
April 1st, 2003, 01:04 PM
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.
April 1st, 2003, 01:08 PM
Nevertheless, thanks a lot. Now I know what to look for. It is going to be much easier.
April 1st, 2003, 01:33 PM
Isnīt there an ::Update() method? If not, try sending WM_PAINT to the window regularly...
April 1st, 2003, 01:39 PM
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
April 2nd, 2003, 02:11 AM
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
April 2nd, 2003, 07:40 AM
April 2nd, 2003, 01:07 PM
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.
April 2nd, 2003, 01:09 PM
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.
April 2nd, 2003, 02:02 PM
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.
April 2nd, 2003, 02:12 PM
Right, my bad. I was thinking PostMessage. Heh...phew....time for lunch.