什么时候需要在TThread中进行同步? [英] When do I need synchronize in TThread?

查看:122
本文介绍了什么时候需要在TThread中进行同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您需要synchronize (yourprocedure)进行设置标签的文字. 但是呢:

I know that you need synchronize (yourprocedure) to set e.g. a label's text. But what about:

  1. 阅读标签的文本.
  2. 切换/设置标签的启用属性.
  3. 调用其他标签的过程/功能(例如onclick事件).

当我需要使用synchronize时,是否有一条容易知道/记住的简单规则?

Is there an easy rule to know/remember when I need to use synchronize?

PS .:同步类似于PostMessage/SendMessage吗?

PS.: Is synchronize similar to PostMessage/SendMessage?

推荐答案

简单的经验法则: ANY VCL UI组件的访问需要同步.这包括读取和写入UI控件属性. Win32用户界面(最著名的对话框,例如MessageBox()TaskDialog())可以直接在工作线程中使用,而无需进行同步.

Easy rule of thumb: ANY access to VCL UI components needs to be synchronized. That includes both reading and writing of UI control properties. Win32 UIs, most notably dialogs like MessageBox() and TaskDialog(), can be used directly in worker threads without synchronizing.

TThread.Synchronize()SendMessage()类似(实际上,它过去曾在Delphi 5及更早版本内部使用SendMessage()实现). TThread.Queue()PostMessage()类似.

TThread.Synchronize() is similar to SendMessage() (in fact, it used to be implemented using SendMessage() internally in Delphi 5 and earlier). TThread.Queue() is similar to PostMessage().

这篇关于什么时候需要在TThread中进行同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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