Jump to content

Refresh label during big loop/elaboration


sagt3k

Recommended Posts

I often work on a database as a data matrix, and then to use nested loops that take time. During the running I use labels and make Application.ProcessMessages to display the updated label.

On using UniGUI on the web, the labels are not updated until end the loop. How can I fix this? During these cycles, I'd use other button to make other function on form, for example, always using Application.ProcessMessages, but that does not work. How can I fix this?

Link to comment
Share on other sites

Thanks for the advice, so how do I refresh a label in a loop?

I have not done this yet with UniGUI but I did it with another framwork. This is one way to do this (I suppose that your process is done on server side):

  • use a thread to process the loop in parallel (parallel thread), so that does not block any kind of messages
  • use a timer to refresh (to generate activity on main thread to, i.e. refresh your label) periodically every N seconds

 

You can do your loop inside a thread. Inside it, you can modify any property provided you have in mind that YOU MUST synchronize this action with the main thread.

 

You can use standard TThread and Synchronize mechanism provided in VCL but I prefer the TJvThread of the JVCL component library (http://jvcl.delphi-jedi.org/) because you can use the thread as any other component, from the standpoint of the accessing to other components of the form, database connections, etc. as long as you make sure that you use a TCriticalSection to ensure correct concurrency updating any property (inside your execute method of the thread, use .Enter method of TCriticalSection, update the label and other properties and, finally use TCriticalSection.Leave method).

 

Please, be very careful avoiding any access to form or components properties out of a critical section.

 

You have to enable the timer before starting the thread and, ontimer event, you could see if the thread is still active. If not, disable the timer.

Link to comment
Share on other sites

I had thought about creating a table that is updated by different threads. You could use the SessionID as a key. And a timer that goes for every xx seconds, a control record to see in what state are the threads, then put into a listbox the same status.

Link to comment
Share on other sites

I had thought about creating a table that is updated by different threads. You could use the SessionID as a key. And a timer that goes for every xx seconds, a control record to see in what state are the threads, then put into a listbox the same status.

Please look at http://forums.unigui.com/index.php?/topic/1479-progressbar-multithreading-demo/

It contains a simple example showing how to do this with UniGUI.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...