procedure TValidThread.Execute;
var
UserName:string;
UserPass:string;
ConnThread:Pointer;
BuffSendData:Array[1..16] of char;
i,j:integer;
AdoConn:TAdoConnection;
AdoQry:TAdoQuery;
UserValid:Boolean;
begin
CoInitialize(NIL);
AdoConn:=TAdoConnection.Create(NIL);
AdoQry:=TAdoQuery.Create(NIL);
AdoConn.ConnectionString:=frmvaliduser.StrConnect;
AdoConn.LoginPrompt:=False;
AdoConn.Connected:=True;
AdoQry.Connection:=AdoConn;
While frmvalidUser.idIsUserValid.Active do
begin
if DeQueue(MyQueue,UserName,Userpass,ConnThread) then
begin
j:=GetTickCount();
try
UserValid:=False;
ZeroMemory(@BuffSendData,16);
try
AdoQry.Active:=False;
AdoQry.SQL.Clear;
AdoQry.SQL.Add('Select * from userdata where 用户姓名='''+UserName+''''+' AND 用户密码='''+UserPass+'''');
AdoQry.Active:=True;
if AdoQry.isempty=False then
begin
UserValid:=True;
end
else
begin
UserValid:=False;
end;
except
end;
j:=GetTickCount()-j;
frmvaliduser.Label9.Caption:=inttostr(j);
if UserValid then
begin
try
BuffSendData[1]:='S';
TIdPeerThread(ConnThread).Connection.WriteBuffer(BuffSendData,16,True);
except
end;
end
else
begin
try
BuffSendData[1]:='F';
TIdPeerThread(ConnThread).Connection.WriteBuffer(BuffSendData,16,True);
except
end;
end;
finally
try
TIdPeerThread(ConnThread).Connection.Disconnect;
except
end;
end;
sleep(5);
end
else
sleep(10);
end;
AdoQry.Close;
AdoQry.Destroy;
AdoConn.Close;
AdoConn.Destroy;
CoInitialize(NIL);
end;
这个线程里的数据库查询代码的执行过程明显比正常的查询过程慢,不明白为什么
var
UserName:string;
UserPass:string;
ConnThread:Pointer;
BuffSendData:Array[1..16] of char;
i,j:integer;
AdoConn:TAdoConnection;
AdoQry:TAdoQuery;
UserValid:Boolean;
begin
CoInitialize(NIL);
AdoConn:=TAdoConnection.Create(NIL);
AdoQry:=TAdoQuery.Create(NIL);
AdoConn.ConnectionString:=frmvaliduser.StrConnect;
AdoConn.LoginPrompt:=False;
AdoConn.Connected:=True;
AdoQry.Connection:=AdoConn;
While frmvalidUser.idIsUserValid.Active do
begin
if DeQueue(MyQueue,UserName,Userpass,ConnThread) then
begin
j:=GetTickCount();
try
UserValid:=False;
ZeroMemory(@BuffSendData,16);
try
AdoQry.Active:=False;
AdoQry.SQL.Clear;
AdoQry.SQL.Add('Select * from userdata where 用户姓名='''+UserName+''''+' AND 用户密码='''+UserPass+'''');
AdoQry.Active:=True;
if AdoQry.isempty=False then
begin
UserValid:=True;
end
else
begin
UserValid:=False;
end;
except
end;
j:=GetTickCount()-j;
frmvaliduser.Label9.Caption:=inttostr(j);
if UserValid then
begin
try
BuffSendData[1]:='S';
TIdPeerThread(ConnThread).Connection.WriteBuffer(BuffSendData,16,True);
except
end;
end
else
begin
try
BuffSendData[1]:='F';
TIdPeerThread(ConnThread).Connection.WriteBuffer(BuffSendData,16,True);
except
end;
end;
finally
try
TIdPeerThread(ConnThread).Connection.Disconnect;
except
end;
end;
sleep(5);
end
else
sleep(10);
end;
AdoQry.Close;
AdoQry.Destroy;
AdoConn.Close;
AdoConn.Destroy;
CoInitialize(NIL);
end;
这个线程里的数据库查询代码的执行过程明显比正常的查询过程慢,不明白为什么
确实一直在循环
但应该不会影响数据库查询部分啊
j:=GetTickCount();
.
.
.
.
j:=GetTickCount()-j;
记录了查询时间
大概要180-300ms
我在主进程里查询只要20ms左右