Link to home
Start Free TrialLog in
Avatar of joely
joely

asked on

Application.ProcessMessage

I have many looping process for...do, while..do, and repeat..until. I should add Application.ProcessMessage inside the looping process.
When I should using Application.ProcessMessage ?

Regards,
Joely
Avatar of kashif063098
kashif063098

i think you should you Application.ProcessMessages whenever you have loops,because its give a chance to your application to process other messages in the queue.

regards
hello Joely
i agree entirely you should always use ProcessMessages while a loop is going on .Without it you have no way to interact with your app or even close it.Even system messages etc will be
queued until the loop stops.
 ¤¤¤¤¤¤¤ InThe ¤¤¤¤¤¤¤

ASKER CERTIFIED SOLUTION
Avatar of tleforge
tleforge

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
All od the guys are right, but I suggest you don't try tleforge's example since you'd have to reset the program....

btw- Barry... PLease tell me how to make those stars..

Cheers,
Viktor
yo hello viktor

it's how i told you before but your keyboard layout is probably
english(us) whereas mine is english(uk)no hangon that work's too um...
procedure(viktor:todo);
begin
goto control panel;
keyboard;
 language;
either select or add english(united states);
set that as default;
then under properties select united states 101;
apply , ok;

then you should be able to hold down alt and press 4111
release alt and anyway it work's for me   er...you were using the keypad were'nt you with the numlock on?
                      ¤
                  <¤   ¤
later dude Barry  <¤   ¤  
                      ¤   ps.floppy's in the post.
I've got U...S.... 101 ...Don't know why it doesn't work.... s***

btw- 10x for the floppy...

P.S. I didn't use NumLock on neither the Caps Lock on... Any other ideas??

Cheers,
Viktor
Avatar of joely

ASKER

Based on your example that you given me, you put Application.ProcessMessages just in second loop and you not put it in first loop. Why ?
How if I have loop more than two, I just put it in last loop.
Actually, as someone pointed out before, this will make your app hang for quite a while.  You may want to put the processmessages in the outer loop instead.  This will still give you a good feel for the timing involved and that's ALL that example was meant to do.

As for 'where' processmessages should go, follow these three rules and you should do well:

  1.  Always try to do without processmessages.
  2.  If possible, where you REALLY NEED for the user to have
      control (as opposed to the application) try to use threads.
  3.  If threads are not possible THEN AND ONLY THEN use
      processmessages.

To answer your question... if it comes down to number 3, use processmessages in WHATEVER loop gives control back to your users without significantly slowing down your application.  There is no 'rule' pertaining to whether processmessages should go in an inner or outer loop.  The best I can do is to tell you to TRY putting it in the loop that iterates fewer times (even though I didn't do that in my example... another bad case of 'do as I say, not as I do;-)

I hope that clarifies things a little more.  If you need anymore help, please feel free to email me at tleforge@hotmail.com.
Just to give you a little background on where I'm coming from...

I'm a clock-cycle counter... if I can find ANY way to make my programs run faster (without negatively impacting the GUI, of course), I'll use it.  I like to tweak the code as much as possible.  Sometimes I drive my employers nuts because they want the product out the door and I'm still tweaking away trying to shave a half second of a particular process.

I have had to, from time to time (and though it went against every fiber of my being), just get the application finished to please the powers-that-be.  And THEN I go back and tweak;-)

I've said all this to say that, if you need to get a project done and using processmessages doesn't slow the app down too much then, by all means, use it.  HOPEFULLY, you can go back and tweak for the next version.  My experience has been otherwise.