为什么我用了两个线程的synchronize后,主线程没有了反应,没有高过tpnormal,而且用一个没关系(100分)

  • 主题发起人 主题发起人 joyprince
  • 开始时间 开始时间
J

joyprince

Unregistered / Unconfirmed
GUEST, unregistred user!
为什么我用了两个线程的synchronize后,主线程没有了反应,没有高过tpnormal,而且用一个没关系
 
两个线程对什么操做?
 
就用canvas不断的画了正方形啊,我运行随便那一个进程都没有问题,只是两个一起就不行 了
 
是同一类型的两个线程实例还是不同类型的线程实例?
你说清楚些,最好把你的代码贴上来。
 
代码贴出来看看,这样才明白。
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls,unit2;
type
TForm1 = class(TForm)
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
UpDown1: TUpDown;
UpDown2: TUpDown;
UpDown3: TUpDown;
Button1: TButton;
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure CheckBox3Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
procedure Edit3Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
ball1,ball2,ball3:TSquareThread;{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.CheckBox1Click(Sender: TObject);
var x,y:integer;
begin
if(checkbox1.checked)=true then
begin
x:=160;
y:=checkbox1.top+checkbox1.height div 2;
ball1:=TSquareThread.Create(clred,x,y);
ball1.resume;
end
else
ball1.terminate;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
var x,y:integer;
begin
if(checkbox2.checked)=true then
begin
x:=160;
y:=checkbox2.top+checkbox2.height div 2;
//edit2.text:='4';
ball2:=TSquareThread.Create(clyellow,x,y);
ball2.resume;
end
else
ball2.terminate;

end;

procedure TForm1.CheckBox3Click(Sender: TObject);
var x,y:integer;
begin
if(checkbox3.checked)=true then
begin
x:=160;
y:=checkbox3.top+checkbox3.height div 2;
ball3:=TSquareThread.Create(clblue,x,y);
ball3.resume;
end
else
ball3.terminate;

end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
if((Edit1.Text='2')and(ball1<>nil))then
ball1.priority:=tpLowest;
if((edit1.text='3')and (ball1<>nil))then
ball1.priority:=tplower;
if((edit1.text='4')and(ball1<>nil))then
ball1.Priority:=tpnormal;
end;

procedure TForm1.Edit2Change(Sender: TObject);
begin
if((Edit1.Text='2')and(ball2<>nil))then
ball2.priority:=tpLowest;
if((edit1.text='3')and (ball2<>nil))then
ball2.priority:=tplower;
if((edit1.text='4')and(ball2<>nil))then
ball2.Priority:=tpnormal;
end;

procedure TForm1.Edit3Change(Sender: TObject);
begin
if((Edit1.Text='2')and(ball3<>nil))then
ball3.priority:=tpLowest;
if((edit1.text='3')and (ball3<>nil))then
ball1.priority:=tplower;
if((edit1.text='4')and(ball3<>nil))then
ball3.Priority:=tpnormal;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if(ball1<>nil)then
ball1.x2:=160;
if(ball2<>nil)then
ball2.x2:=160;
if(ball3<>nil)then
ball3.x2:=160;
end;

end.

是同一类型的线程实例
 
后退
顶部