从CreateAnonymousThread更新VCL组件 [英] Update a VCL component from CreateAnonymousThread

查看:236
本文介绍了从CreateAnonymousThread更新VCL组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎哪些同步不能使用创建的线程使用 CreateAnonymousThread ,所以问题是:我如何可以使用CreateAnonymousThread创建的线程内部更新VCL组件?

It seems which Synchronize cannot be used from a Thread created using CreateAnonymousThread, so the question is : How i can update a VCL component from inside of a Thread created using CreateAnonymousThread?

TThread.CreateAnonymousThread(procedure
 begin
  //do something
  UpdateCompnent();//how I can update a VCL component from here?   
 end
).Start;


推荐答案

可以使用同步在这种情况下,例如:

You can use synchronize in this case, e.g.:

TThread.Synchronize(nil, procedure begin UpdateComponent(); end);

如果要在主线程中执行异步方法调用,可以使用 TThread.Queue ,例如:

And if you want asynchronous method call execution within the main thread, you can use TThread.Queue, e.g.:

TThread.Queue(nil, procedure begin UpdateComponent(); end);

这篇关于从CreateAnonymousThread更新VCL组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆