I used this http://delphi.about.com/od/kbthread/a/thread-gui.htm tutorial to create a class that asynchronously downloads a file from the Internet to another thread using TDownLoadURL . I did this because I want to download the file without blocking the user interface stream, so that the program does not stop responding during large downloads, the progress bar could update, etc.
I have a problem because although I did the download in another thread (inheriting from TThread and doing the work in the Execute method), the GUI thread seems to be blocked and does not process messages until the download is complete. Here is the code for my class: http://codepad.org/nArfOPJK (it's just 99 lines, a simple class). I accomplish this through this, in an event handler for clicking a button:
var frame: TTProgressFrame; dlt: TDownloadThread; begin dlt := TDownloadThread.Create(True); dlt.SetFile('C:\ohayo.zip'); dlt.SetURL('http://download.thinkbroadband.com/512MB.zip'); dlt.SetFrame(frame); dlt.SetApp(Application); dlt.Start;
Note. The SetApp method was used when I manually called app.ProcessMessages from the UpdateDownloadProgress method of my TDownloadThread class. This will keep the GUI from immunity, but it led the progress bar to work quite oddly (the moving light-emitting light indication of the progress bar is too fast), so I deleted it. I want to fix this correctly, and if I need to call ProcessMessages , then there is no point in multithreading it.
Can someone help me fix this problem? Thanks.
Kokonotsu
source share