可
可口白菜
Unregistered / Unconfirmed
GUEST, unregistred user!
我用多线程但是线程执行时就没法对用户界面进行操作了(无法点击任何控件)
我是这么实现的
type TestThread=Class(TThread)
private
FileName:string;
protected
procedure execute;override;
proceduredo
message;
public
constructor create(suspend:Boolean;FName:string);
type TestThread1=Class(TThread)
private
FileName:string;
protected
procedure execute;override;
proceduredo
message;
public
constructor create(suspend:Boolean;FName:string);
.....
constructor TestThread.Create(Suspend:boolean;FName:string);
begin
inherited Create(Suspend);
FileName:=FName;
ExitOnTerminated:=True;
end;
procedure TestThread.execute;
begin
Synchronize(domessage);
end;
procedure TestThread.domessage;
begin
Form1.Memo1.lines.add(FileName);
end;
constructor TestThread1.Create(Suspend:boolean;FName:string);
begin
inherited Create(Suspend);
FileName:=FName;
ExitOnTerminated:=True;
end;
procedure TestThread1.execute;
begin
Synchronize(domessage);
end;
procedure TestThread1.domessage;
begin
Form1.Memo1.lines.add(FileName);
end;
procedure Form1.button1onclick;
var TestTh:TestThread;
i:integer;
begin
For i:=0 to 255do
begin
TestTh :=TestThread.Create(False,Inttostr(i);
TestTh.Resume;
end;
end;
procedure Form1.button2onclick;
var TestTh:TestThread1;
i:integer;
begin
For i:=0 to 255do
begin
TestTh :=TestThread1.Create(False,Inttostr(i);
TestTh.Resume;
end;
end;
界面上有两个memo,一个edit,两个按钮(button1,button2)
但是我一点击第一个按钮以后,其他的就无法作了,包括第二个按钮的点击和edit 的输入
怎么样才能实现用户界面的操作和这些线程的同步,这些线程能不能只放在后台
而且线程能不能对其对CPU资源占用作限制,因为我做的线程是为了处理图片,单作会
占用99%的CPU资源
谢谢各位大虾了
我是这么实现的
type TestThread=Class(TThread)
private
FileName:string;
protected
procedure execute;override;
proceduredo
message;
public
constructor create(suspend:Boolean;FName:string);
type TestThread1=Class(TThread)
private
FileName:string;
protected
procedure execute;override;
proceduredo
message;
public
constructor create(suspend:Boolean;FName:string);
.....
constructor TestThread.Create(Suspend:boolean;FName:string);
begin
inherited Create(Suspend);
FileName:=FName;
ExitOnTerminated:=True;
end;
procedure TestThread.execute;
begin
Synchronize(domessage);
end;
procedure TestThread.domessage;
begin
Form1.Memo1.lines.add(FileName);
end;
constructor TestThread1.Create(Suspend:boolean;FName:string);
begin
inherited Create(Suspend);
FileName:=FName;
ExitOnTerminated:=True;
end;
procedure TestThread1.execute;
begin
Synchronize(domessage);
end;
procedure TestThread1.domessage;
begin
Form1.Memo1.lines.add(FileName);
end;
procedure Form1.button1onclick;
var TestTh:TestThread;
i:integer;
begin
For i:=0 to 255do
begin
TestTh :=TestThread.Create(False,Inttostr(i);
TestTh.Resume;
end;
end;
procedure Form1.button2onclick;
var TestTh:TestThread1;
i:integer;
begin
For i:=0 to 255do
begin
TestTh :=TestThread1.Create(False,Inttostr(i);
TestTh.Resume;
end;
end;
界面上有两个memo,一个edit,两个按钮(button1,button2)
但是我一点击第一个按钮以后,其他的就无法作了,包括第二个按钮的点击和edit 的输入
怎么样才能实现用户界面的操作和这些线程的同步,这些线程能不能只放在后台
而且线程能不能对其对CPU资源占用作限制,因为我做的线程是为了处理图片,单作会
占用99%的CPU资源
谢谢各位大虾了