Recent

Author Topic: gui application with long operation  (Read 467 times)

Чебурашка

  • Hero Member
  • *****
  • Posts: 568
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
gui application with long operation
« on: May 19, 2022, 03:17:38 pm »
Hi,
I am almost sure this is a old topic, please suggest relevant messages if there are.

Have a GUI application with one Form, with a button. When one clicks the button a long operation starts (duration can vary from few msec to several tens of seconds).

Is there anything ready or, if not, what is the recommended approach to:

1. avoid blocking the Form
2. give a notification if the actual duration of the operation exceeds x msecs (something like a busy wait screen that appears if operation is too long)

Thank you
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11445
  • FPC developer.
Re: gui application with long operation
« Reply #1 on: May 19, 2022, 04:48:51 pm »
If you can break up the long operation (e.g. it is a FOR loop, and you can run code every so many iterations), then you can mess around with application.processmessages. (search on the forum)

In other cases, when the code can't be interrupted in any way, moving the code to a thread is the only solution, and hope that it eventually finishes.

 

TinyPortal © 2005-2018