DelphiFAQ Home Search:

Avoiding Application.ProcessMessages

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Q:
I am writing a procedure, which may take a long time to execute. I want
the user to be able to stop it at any point of execution. I can use
Application.ProcessMessages to handle a click of the 'STOP' button.
I also thougt about creating a new thread for the procedure.
In either case I have to check for a variable 'ProcedureStopped' (with
Application.ProcessMessages) or I have to check for MyThread.Terminated.

Both of these require frequent polling. I'd prefer some kind of
interrupt to exit the procedure.

A:
By Hallvard Vassbotn, hallvard@millionhandshakes.com :

Unfortunately, by default the VCL does not have a very thread-friendly
mainthread message loop. It is possible to override the message loop by
hooking Application.OnIdle and call MsgWaitForMultipleObjects there.
Doing this you can build your own multithread aware message loop and
thus easiliy get notified of events and other signals raised from
secondary threads.


Content-type: text/html

Comments:

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: