Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

program frozen while in cycle

Status
Not open for further replies.

d3g3sh

Technical User
May 5, 2006
8
SK
How can I prevent program from freezing while in cycle? For example my program waits for data from serial port in cycle and while waiting it does not respnd. Is there a way to run that cycle in background or something?
 
Do you mean you are using a Do/while Repeat/until Type loop?
If so you should always include
application.processmessages within the loop
Code:
repeat
application.processmessages
// what you want to do here
until thecowscomehome
This allows windows to process keystrokes/mouse input while the loop is running, but if the loop is short even this might stop an instant response. In this case you need to look at multithreading or using a timer to do your external access.
The comms interface component I use 'CPortLib' is multithreaded itsself and so dosnt have these problems.




Steve: Delphi a feersum engin indeed.
 
Yes, i am using mainly repeat/until and for ... do begin...
Well, it still "freezes". I used it with some simple cycle like:

repeat
application.processmessages;
memo1.lines.add(inttostr(i));
inc(i);
until i=1000000;

and it didnt helped. Isnt there something else?
 
Quick and dirty for COM port access: use a timer and poll the channel in every tick; set the timer cycle at 50..100 mSecs.

The Windows way for any loop: make your loops in another thread outside the main (VCL) one. Beware synchronization! Get some good reads about threads before starting (the 'net have plenty).

Specialized strategies for I/O access (the COM port are I/O devices): use overlapping reads in the main thread, but they are very tricky if you are not used with; multithreading is easier.

buho (A).
 
check out turbopower's (commercial) APRO suite :

since they no longer exist, they gave the code to the opensource community. Their comport component is multithreaded and of the most stable ones I ever used!


Cheers,

Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top