Update a VCL component from CreateAnonymousThread

前端 未结 3 1230
悲&欢浪女
悲&欢浪女 2021-01-02 15:50

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 Th

相关标签:
3条回答
  • 2021-01-02 16:09

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

    0 讨论(0)
  • 2021-01-02 16:17

    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 讨论(0)
  • 2021-01-02 16:29

    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);
    
    0 讨论(0)
提交回复
热议问题