![]() |
AW: Wininet asynchronous download
Ich habe den Code jetzt nur überflogen, aber das hier sieht für mich ziemlich blockierend aus:
Delphi-Quellcode:
repeat
currentBytes := inet.ReadData(@buff, BUFFER_SIZE); buff[currentBytes] := 0; BlockWrite(f, buff, currentBytes); until currentBytes = 0; |
AW: Wininet asynchronous download
Danke fur Hilfe.
Ich habe versucht jetzt mit WriteFile async zu schreiben. Datei wird geschrieben aber wieder ist alles frozen, bis Download fertig.
Delphi-Quellcode:
Ist das normal und ich brauche TThread fur async download?
function DownloadAsync(const Url, FileName: string): Boolean;
const BUFFER_SIZE = 1024 * 4; var inet: TAsyncInet; host, path: string; buff: array[0..BUFFER_SIZE - 1] of Byte; currentBytes, writtenBytes: DWORD; hFile: THandle; oFile: OVERLAPPED; written: Boolean; begin result := false; inet := TAsyncInet.Create; try ExtractUrlTo(Url, host, path); if inet.Connect('Test', host) then if inet.SendRequest(_GET, path, '', '') then begin writtenBytes := 0; hFile := CreateFile(PChar(FileName), GENERIC_WRITE, 0, nil, CREATE_ALWAYS, FILE_FLAG_OVERLAPPED, 0); if hFile <> INVALID_HANDLE_VALUE then try ZeroMemory(@oFile, SizeOf(OVERLAPPED)); oFile.Offset := $FFFFFFFF; oFile.OffsetHigh := $FFFFFFFF; oFile.hEvent := CreateEvent(nil, false, false, nil); repeat ZeroMemory(@buff, BUFFER_SIZE); currentBytes := inet.ReadData(@buff, BUFFER_SIZE); buff[currentBytes] := 0; written := WriteFile(hFile, @buff, currentBytes, @writtenBytes, @oFile); if not written then begin if GetLastError = ERROR_IO_PENDING then begin if WaitForSingleObject(oFile.hEvent, 20000) = WAIT_TIMEOUT then break; end; end; until (currentBytes = 0); CloseHandle(oFile.hEvent); result := true; finally CloseHandle(hFile); end; end; finally inet.Free; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:17 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz