我做了个简单的线程,代码如下:
var
Form1: TForm1;
thread1:Tmythread; procedure TForm1.Button1Click(Sender: TObject);
begin
thread1:= Tmythread.Create(false);
end; procedure TForm1.Button2Click(Sender: TObject);
begin
thread1.Suspend;
end; procedure TForm1.Button3Click(Sender: TObject);
begin
thread1.Resume;
end; end. 线程的代码: uses
Messages, SysUtils,Windows,Variants, Classes, Graphics, Controls, Forms,
Dialogs,StdCtrls; type
Tmythread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end; implementation
uses
Unit1; procedure Tmythread.Execute;
var
i:longint;
DC:HDC;
S:string;
begin DC:=GetDC(Form1.Handle);
for i:=0 to 500000 do begin
S:=Inttostr(i);
Textout(DC,10,10,Pchar(S),length(S));
end;
ReleaseDC(Form1.Handle,DC);
end;
end.
问题是我可以启动线程,但是按下button2挂起线程后程序就不响应了!
请高手帮下忙,看下我的问题出现在哪里.
谢谢!
var
Form1: TForm1;
thread1:Tmythread; procedure TForm1.Button1Click(Sender: TObject);
begin
thread1:= Tmythread.Create(false);
end; procedure TForm1.Button2Click(Sender: TObject);
begin
thread1.Suspend;
end; procedure TForm1.Button3Click(Sender: TObject);
begin
thread1.Resume;
end; end. 线程的代码: uses
Messages, SysUtils,Windows,Variants, Classes, Graphics, Controls, Forms,
Dialogs,StdCtrls; type
Tmythread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end; implementation
uses
Unit1; procedure Tmythread.Execute;
var
i:longint;
DC:HDC;
S:string;
begin DC:=GetDC(Form1.Handle);
for i:=0 to 500000 do begin
S:=Inttostr(i);
Textout(DC,10,10,Pchar(S),length(S));
end;
ReleaseDC(Form1.Handle,DC);
end;
end.
问题是我可以启动线程,但是按下button2挂起线程后程序就不响应了!
请高手帮下忙,看下我的问题出现在哪里.
谢谢!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货