X
xiaoyue_a
Unregistered / Unconfirmed
GUEST, unregistred user!
我用tcpclient和tcpserver传文件。在传输的过程中想显示进度、速度
开始这么写的
while aStream.Position < aStream.Sizedo
begin
if aStream.Size - aStream.Position >= SizeOf(Buf) then
ReadCount := SizeOf(Buf)
else
ReadCount := aStream.Size - aStream.Position;
aStream.ReadBuffer(Buf, ReadCount);
aIdTCPClient.WriteBuffer(Buf, ReadCount);
{
显示进度的操作
}
application.ProcessMessages;
end;
当我把显示进度的操作做成一个线程时,上传文件时程序会死掉 不知道是什么原因
进程是这么写的
procedure UploadMonitor.Execute;
begin
csize := cFileStream.Position;
while csize < cFileStream.Sizedo
begin
if cFileStream <> nil then
begin
csize := cFileStream.Position;
if cFileStream.Size > 1073741824 then
ProBar.Position := Round(csize / 1024)
else
ProBar.Position := csize;
lbpercent.Caption := IntToStr(Round(csize * 100 / cFileStream.Size)) + '/100%';
lbspeed.Caption := IntToStr(Round((csize - bsize) * 2 / 1024)) + 'K/S';
bsize := csize;
sleep(500);
end
else
break;
end;
end;
开始这么写的
while aStream.Position < aStream.Sizedo
begin
if aStream.Size - aStream.Position >= SizeOf(Buf) then
ReadCount := SizeOf(Buf)
else
ReadCount := aStream.Size - aStream.Position;
aStream.ReadBuffer(Buf, ReadCount);
aIdTCPClient.WriteBuffer(Buf, ReadCount);
{
显示进度的操作
}
application.ProcessMessages;
end;
当我把显示进度的操作做成一个线程时,上传文件时程序会死掉 不知道是什么原因
进程是这么写的
procedure UploadMonitor.Execute;
begin
csize := cFileStream.Position;
while csize < cFileStream.Sizedo
begin
if cFileStream <> nil then
begin
csize := cFileStream.Position;
if cFileStream.Size > 1073741824 then
ProBar.Position := Round(csize / 1024)
else
ProBar.Position := csize;
lbpercent.Caption := IntToStr(Round(csize * 100 / cFileStream.Size)) + '/100%';
lbspeed.Caption := IntToStr(Round((csize - bsize) * 2 / 1024)) + 'K/S';
bsize := csize;
sleep(500);
end
else
break;
end;
end;