C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old April 1st, 2003, 02:15 AM
marek_haj's Avatar
marek_haj marek_haj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: currently Lisbone, Portugal
Posts: 154 marek_haj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 28 m
Reputation Power: 6
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.
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

Reply With Quote
  #2  
Old April 1st, 2003, 02:38 AM
MJEggertson MJEggertson is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Seattle WA
Posts: 863 MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 sec
Reputation Power: 8
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.

Reply With Quote
  #3  
Old April 1st, 2003, 06:15 AM
marek_haj's Avatar
marek_haj marek_haj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: currently Lisbone, Portugal
Posts: 154 marek_haj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 28 m
Reputation Power: 6
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

Reply With Quote
  #4  
Old April 1st, 2003, 09:40 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,803 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 11 h 55 m 53 sec
Reputation Power: 437
Quote:
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.

Reply With Quote
  #5  
Old April 1st, 2003, 10:39 AM
marek_haj's Avatar
marek_haj marek_haj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: currently Lisbone, Portugal
Posts: 154 marek_haj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 28 m
Reputation Power: 6
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

Reply With Quote
  #6  
Old April 1st, 2003, 01:04 PM
MJEggertson MJEggertson is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Seattle WA
Posts: 863 MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 sec
Reputation Power: 8
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.

Reply With Quote
  #7  
Old April 1st, 2003, 01:08 PM
marek_haj's Avatar
marek_haj marek_haj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: currently Lisbone, Portugal
Posts: 154 marek_haj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 28 m
Reputation Power: 6
Nevertheless, thanks a lot. Now I know what to look for. It is going to be much easier.
Best greets
MArek

Reply With Quote
  #8  
Old April 1st, 2003, 01:33 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
Quote:
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...
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #9  
Old April 1st, 2003, 01:39 PM
marek_haj's Avatar
marek_haj marek_haj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: currently Lisbone, Portugal
Posts: 154 marek_haj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 28 m
Reputation Power: 6
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.
Thanks for the post
Best greets
MArek

Reply With Quote
  #10  
Old April 2nd, 2003, 02:11 AM
marek_haj's Avatar
marek_haj marek_haj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: currently Lisbone, Portugal
Posts: 154 marek_haj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 28 m
Reputation Power: 6
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

Reply With Quote
  #11  
Old April 2nd, 2003, 07:40 AM
3dfxMM 3dfxMM is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 266 3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 19 h 1 m 34 sec
Reputation Power: 12
Try UpdateWindow.

Reply With Quote
  #12  
Old April 2nd, 2003, 01:07 PM
MJEggertson MJEggertson is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Seattle WA
Posts: 863 MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 sec
Reputation Power: 8
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.

Reply With Quote
  #13  
Old April 2nd, 2003, 01:09 PM
MJEggertson MJEggertson is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Seattle WA
Posts: 863 MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 sec
Reputation Power: 8
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.

Reply With Quote
  #14  
Old April 2nd, 2003, 02:02 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
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?

Reply With Quote
  #15  
Old April 2nd, 2003, 02:12 PM
MJEggertson MJEggertson is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Seattle WA
Posts: 863 MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 sec
Reputation Power: 8
Right, my bad. I was thinking PostMessage. Heh...phew....time for lunch.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Program window does not refresh. What is wrong ???


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread