Home TTask in Delphi 10.2
Reply: 1

TTask in Delphi 10.2

Andy Murphy
1#
Andy Murphy Published in 2018-01-12 16:12:19Z

not used TTask before and its a simple thing im trying to do.

While the main form executes a procedure (DoAnalyse) id like to display the TActivityIndicator on my main form without it slowing as the thread does the work. I used to use a progress bar but would prefer to use the more modern Activity Indicator.

I Have tried it two ways:

A simple:

Ttask.Run(DoAnalyse);

and

Task := TTask.Create( procedure begin DoAnalyse; end); Task.Start;

it executes perfectly and my activity indicator behaves smoothly.

Problem is when the procedure is finished the main form is locked and doesn't respond at all. im guessing I have to put some kind of call back to the main thread but cant find out how to do it.

Any ideas?

Remy Lebeau
2#
Remy Lebeau Reply to 2018-01-12 17:32:18Z

TTask doesn't have an event when it stops running. Your task procedure needs to use TThread.Synchronize() or TThread.Queue() (or any other inter-thread mechanism of your choosing) to notify the main thread before it exits.

Otherwise, use TThread instead of TTask. TThread has an OnTerminate event.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.317269 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO