線程(0分)

  • 主题发起人 主题发起人 liuxiangsoft
  • 开始时间 开始时间
L

liuxiangsoft

Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个线程, 好像没有问题的
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

SusTest = class(TThread)
private
{ Private declarations }
protected
procedure Execute;
override;
end;

var
Form1: TForm1;
hMain: THandle;
implementation
{$R *.dfm}
{ SusTest }
procedure SusTest.Execute;
begin
MessageBox(0, 'Thread started', 'hello', MB_ICONINFORMATION);
SuspendThread(hMain);
// 弹出消息框
MessageBox(GetActiveWindow(),
'The Primary thread is suspended.'#13#10 +
'It no longer responds to input and produces no output.'#13#10 +
'Press OK to resume the primary thread & exit this secondary thread.'#13#10,
'SchedLab', 0);
// 恢复主线程
ResumeThread(hMain);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
t: SusTest;
begin
t := SusTest.Create(True);
t.Resume;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
hMain := GetCurrentThread;
DuplicateHandle(GetCurrentProcess, hMain,
GetCurrentProcess, @hMain,
0, False,
DUPLICATE_SAME_ACCESS);
end;

end.
 
www.source520.com 再次更新近3万代码,全部免费免注册狂下载
 
后退
顶部