Registriert seit: 30. Sep 2006
Ort: Gundelfingen
1.109 Beiträge
Delphi 2007 Professional
|
Re: Threads nacheinander ausführen
1. Feb 2009, 23:21
Delphi-Quellcode:
function MyWaitFor(Event: THandle): Boolean; // von negaH: [url]http://www.delphipraxis.net/post696510.html#696510[/url]
begin
Result := False;
while not Result do
case MsgWaitForMultipleObjects(1, Event, False, INFINITE, QS_ALLINPUT) of
WAIT_OBJECT_0:
Result := True;
WAIT_OBJECT_0 + 1:
begin
Application.ProcessMessages;
if Application.Terminated then Exit;
end;
else
RaiseLastWin32Error;
end;
end;
constructor TDownloadUpdate.Create(aFilename, aURL: string; aFinishEvent: Cardinal);
begin
inherited Create(True);
fFile := aFilename;
fUrl := aURL;
fFinishEvent := aFinishEvent;
FreeOnTerminate := True;
resume;
end;
procedure TDownloadUpdate.Execute;
var
www: TIdHttp;
fs: TFileStream;
begin
inherited;
www:=TIdHttp.Create( nil);
[ url]www.Port:=81;[/ url] // Nur testweise, da Apache auf 81 lauscht.
try
try
ForceDirectories(ExtractFilePath(ParamStr(0))+' \Updates\');
fs:=TFileStream.Create(ExtractFilePath(ParamStr(0))+' Updates\'+fFile, fmCreate);
www.Get(fUrl, fs);
except
//
end;
finally
[ url]www.free;[/ url]
fs.Free;
SetEvent(fFinishEvent);
end;
end;
procedure TUpdater.DownloadUpdate(i: Integer);
var
Event: THandle;
begin
Event := CreateEvent( nil, False, False, ' ThreadFinished');
TDownloadUpdate.Create(GetUpdateInfo(i, ' filename'), GetUpdateInfo(i, ' url'), Event);
MyWaitFor(Event);
CloseHandle(Event);
end;
Dominik Wer anderen eine Grube gräbt, hat ein Gruben-Grab-Gerät!
|
|
Zitat
|