P
pogoo
Unregistered / Unconfirmed
GUEST, unregistred user!
我开了4个线程,同时向一个SMTP服务器发送信件!大致的代码如下:
procedure TMainForm.Button1Click(Sender: TObject);
begin
for i := 0 to 3do
begin
OnlineThread:= TOnlineThread.Create(SmtpServerStr);
OnlineThread.FreeOnTerminate := True;
OnlineThread.OnTerminate := ThreadsDone;
if Abort then
Exit;
OnlineThread.Resume;
end;
end;
procedure MyThread.Execute;
var
iCount : integer;
begin
while not EoF(mytext)do
begin
......
inc(iCount);
end;
end;
procedure TMainForm.ThreadsDone(Sender: TObject);
begin
inc(ThreadsTerminateCount);
if ThreadsTerminateCount = 4 then
begin
ThreadsTerminateCount := 0;
CloseFile(mytext);
ShowMessage('All threads Complete!');
end;
end;
问题是:我在Execute中对每个线程的iCount分别计数,然后分别显示到4个Panel上,但是
怪事来了!我如果不在程序中加上sleep(xx),则计数只在一个panel上显示,别的线程就
好象并没运行。但如果加上sleep(xx),则必须要根据线程数来调整xx的值,并且与放置的
位置有关系,这样才能在4个panel上分别显示iCount值。如果放置的位置不对,或xx设置的
部队,则有时在1个panel上显示、有时在2个panel上显示、有时在3个panel上显示。这到底
是怎么回事,我都快给整疯了!!!!大富翁们!救救俺吧!!!!!!!!!!!!
procedure TMainForm.Button1Click(Sender: TObject);
begin
for i := 0 to 3do
begin
OnlineThread:= TOnlineThread.Create(SmtpServerStr);
OnlineThread.FreeOnTerminate := True;
OnlineThread.OnTerminate := ThreadsDone;
if Abort then
Exit;
OnlineThread.Resume;
end;
end;
procedure MyThread.Execute;
var
iCount : integer;
begin
while not EoF(mytext)do
begin
......
inc(iCount);
end;
end;
procedure TMainForm.ThreadsDone(Sender: TObject);
begin
inc(ThreadsTerminateCount);
if ThreadsTerminateCount = 4 then
begin
ThreadsTerminateCount := 0;
CloseFile(mytext);
ShowMessage('All threads Complete!');
end;
end;
问题是:我在Execute中对每个线程的iCount分别计数,然后分别显示到4个Panel上,但是
怪事来了!我如果不在程序中加上sleep(xx),则计数只在一个panel上显示,别的线程就
好象并没运行。但如果加上sleep(xx),则必须要根据线程数来调整xx的值,并且与放置的
位置有关系,这样才能在4个panel上分别显示iCount值。如果放置的位置不对,或xx设置的
部队,则有时在1个panel上显示、有时在2个panel上显示、有时在3个panel上显示。这到底
是怎么回事,我都快给整疯了!!!!大富翁们!救救俺吧!!!!!!!!!!!!