开发者

Update a VCL component from CreateAnonymousThread

开发者 https://www.devze.com 2023-03-20 23:38 出处:网络
It seems which Synchronize cannot be usedfrom a Thread created using CreateAnonymousThread, so the question is : How i can update a VCL component from inside 开发者_如何学Cof a Thread created using Cr

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 开发者_如何学Cof 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);

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);


You could also use PostMessage to safely queue, or SendMessage to safely synchronize from an anonymous thread.


You can use PostMessage(Form.Handle, WM_UPDATEMYCOMP, 0, 0);

You can define your own message id, wparam, lparam, with a bit of work you can turn them into more complicated parameters.

0

精彩评论

暂无评论...
验证码 换一张
取 消