ProcessMessages和应用程序的使用 [英] ProcessMessages and use of application

查看:182
本文介绍了ProcessMessages和应用程序的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如果使用允许我使用整个应用程序的ProcessMessages是合法的。

I need to know if use of ProcessMessages that allow me to use entire application is legal.

伪代码:

主线程按钮调用 - 搜索。

Main thread button call - search.

procedure ButtonOnClick;
begin
    var1 = ExecuteSearch();
end;    

function ExecuteSearch:Something;
begin
 thread.StartThread;
 while thread.Finished do
 Application.ProcessMessages;
 result := something;
end;

当我使用这个结构时,我可以点击我的软件的其他部分并使用它。但是我不知道这是如何工作的。而且如果它的安全。

When I use this construction I can click other parts of my software and use it. But I don't know how this works. And if its safe.

推荐答案

尽管代码是安全的,但您还可以做的是在线程上使用OnTerminate事件重新开始这样你就可以让Delphi控制如何从后台线程发回到主线程。在内部,它使用线程的Synchronize方法,您可以使用它来让线程将中间进度信息发布到主线程。

Though the code is safe, what you could also do is use the OnTerminate event on the thread you're starting. This way you let Delphi control how to post back from the background thread to the main thread. Internally it uses the thread's Synchronize method, which you can use yourself to let the thread post intermediate progress information to the main thread.

这篇关于ProcessMessages和应用程序的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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