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.
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.
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!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.