gpt4 book ai didi

multithreading - 从 CreateAnonymousThread 更新 VCL 组件

转载 作者:行者123 更新时间:2023-12-03 14:46:29 24 4
gpt4 key购买 nike

看来是Synchronize不能从使用 CreateAnonymousThread 创建的线程中使用,所以问题是:如何从使用 CreateAnonymousThread 创建的线程内部更新 VCL 组件?

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

最佳答案

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

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

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

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

关于multithreading - 从 CreateAnonymousThread 更新 VCL 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6739595/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com