在单独的线程中加载数据期间表单被冻结
我使用 TIdHTTP 组件在单独的线程中从银行加载 xml 数据,但我的表单在那段时间被冻结......
可能是什么问题?
我有一个主窗体和线程类,在线程类中我有一个名为 loadData 的方法,在 thread::Execute i Synchronize(loadData); 上
当单击按钮时,我创建了线程类的实例,如 testThread *t=new testThread(false);
这就是
当我单击按钮时主窗体冻结的全部内容? 即使单独的线程也没有帮助???
请帮忙!!!
I use TIdHTTP component to load xml data from a bank in a seperate thread but my form is getting freezed during that time...
what could be the problem ?
I have a main form and thread class, in thread class i have a method called loadData and on thread::Execute i Synchronize(loadData);
when button gets clicked I created the instance of thread class like testThread *t=new testThread(false);
and that's all
when i click the button the main form freezes?
even seperate thread didn't help????
Please help!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Synchronize()
正在主线程上下文中运行您的loadData()
方法,而不是在工作线程上下文中。这就是为什么当loadData()
繁忙时主线程会阻塞。您滥用了Synchronize()
,导致您的线程无用。您需要在Synchronize()
之外完成大部分线程工作,然后仅在需要时使用Synchronize()
在主线程中执行小更新,例如显示状态(即使如此,Synchronize()
并不总是最佳选择)。Synchronize()
is running yourloadData()
method in the context of the main thread, not in the context of your worker thread. That is why your main thread blocks whileloadData()
is busy. You are misusingSynchronize()
, rendering your thread useless. You need to do the bulk of your thread work outside ofSynchronize()
, and then useSynchronize()
only to perform small updates in the main thread when needed, like displaying status (even then,Synchronize()
is not always the best choice for that).