subthread(handling busy operation) notify mainthread to update UI
来源:互联网 发布:返利网源码下载 编辑:程序博客网 时间:2024/06/05 17:36
Call PostMessage inside TMyThread.Execute to tell Main Form to update UI
unit MyConsts;
interface
uses Messages;
const
WM_UPDATE_STATUS = WM_USER + 1;
implementation
end.
///////////////////////////////////////////////////////////////////////
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, MyConsts;
type
TForm1 = class(TForm)
btnSpawn: TButton;
pgsBar: TProgressBar;
lblPC: TLabel;
procedure btnSpawnClick(Sender: TObject);
private
{ Private declarations }
protected
procedure OnUpdateStatus(var Msg: TMessage); message WM_UPDATE_STATUS;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.btnSpawnClick(Sender: TObject);
var
AThread: TMyThread;
begin
AThread := TMyThread.CreateNew(100000, Handle);
AThread.Resume;
end;
procedure TForm1.OnUpdateStatus(var Msg: TMessage);
begin
pgsBar.Position := Msg.WParam;
lblPC.Caption := Format('%d%s', [Msg.WParam, '%']);
end;
end.
///////////////////////////////////////////////////////////////////////
unit Unit2;
interface
uses
Classes, Windows, Messages;
type
TMyThread = class(TThread)
private
{ Private declarations }
FHandle: THandle;
FCounter: Integer;
protected
procedure Execute; override;
public
constructor CreateNew(Counter: Integer; AHandle: THandle);
end;
implementation
uses MyConsts;
constructor TMyThread.CreateNew(Counter: Integer; AHandle: THandle);
begin
inherited Create(true);
FCounter := Counter;
FHandle := AHandle;
FreeOnTerminate := true;
end;
procedure TMyThread.Execute;
var
i, r: Integer;
begin
for i := 1 to 100 do
begin
PostMessage(FHandle, WM_UPDATE_STATUS, i, 0);
Sleep(100);
end;
end;
end.
- subthread(handling busy operation) notify mainthread to update UI
- use delegate to update UI
- MainThread
- Too busy to update blog--I must be more selfconfident
- Handling UI events
- (5)Handling UI events
- Busy to finish the work.
- 并发update/update引起的buffer busy wait
- solrCloud Update Request Handling 更新索引流程
- The last update operation tried to add the file 'xxx.java',but the file already exists universioned
- Android UI Operation in Thread
- Busy! ? !
- distributed update operation failed ,rollback required
- 【MonogoDB】The high update operation of MongoDB
- Implemented the interface INotifyPropertyChanged can inform UI to update the values.
- Update Command UI Handlers Do Not Work for Menu Attached to a Dialog Box
- Update the link url in the Moss 2010 to call SP.UI.ModalDialog.showModalDialog
- stop subthread example with Event
- ORACLE 截断字符串
- [转]prototype.js函数介绍
- 生活索引
- 什么是 System.Transactions(msdn)?
- 精讲MySQL 数据库的
- subthread(handling busy operation) notify mainthread to update UI
- 咨询公司细数ERP失败10大祸首
- 如何和何时使用多线程
- POJ 1781 的进一步优化
- SQL語法大全
- VC多工具栏停靠
- 忘记mysql密码
- 我理解的组件和控件的区别
- RIA技术选择