Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Delphi GUI Programming with FireMonkey

You're reading from   Delphi GUI Programming with FireMonkey Unleash the full potential of the FMX framework to build exciting cross-platform apps with Embarcadero Delphi

Arrow left icon
Product type Paperback
Published in Oct 2020
Publisher Packt
ISBN-13 9781788624176
Length 546 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Andrea Magni Andrea Magni
Author Profile Icon Andrea Magni
Andrea Magni
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Section 1: Delphi GUI Programming Frameworks
2. Introducing the FireMonkey Framework FREE CHAPTER 3. Exploring Similarities and Differences with VCL 4. Section 2: The FMX Framework in Depth
5. Mastering Basic Components 6. Discovering Lists and Advanced Components 7. Using FireDAC in FMX Applications 8. Implementing Data Binding 9. Understanding FMX Style Concept 10. Divide and Conquer with TFrameStand 11. Building Responsive UIs 12. Orchestrating Transitions and Animations 13. Section 3: Pushing to The Top: Advanced Topics
14. Building Responsive Applications 15. Exploring Cross-Platform Services 16. Learning about FMX 3D Capabilities 17. Other Books You May Enjoy

Waiting for a task to complete

Assume that we have a task reference (ITask) and we want to wait (synchronously) for its completion before proceeding further.

The ITask.Wait method is provided exactly for this purpose. It also accepts an argument for the desired timeout, making it very easy to fine-tune the operation. The following code shows the ITask.Wait method:

var
LTask: ITask;
begin
LTask := TTask.Run(
procedure
begin
Sleep(5000); // Do something...
end
);

LTask.Wait();
// Completed
end;

In the previous code, assuming that we are running this code in the main/UI thread, the expected behavior here is that the task will run in the background, and the main/UI thread will synchronously wait for the task completion. Obviously, especially if the task is not immediate, this will block the main/UI thread so this is not a good practice to achieve responsiveness.

The following code shows how we can try to avoid blocking the main/UI thread for the whole execution...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime