URL::downloadToFile issues

I’ve written a small download queue class, which allows me to add downloads to it and it then downloads up to “n” files (default 4) at the same time.

Once a file finishes, it copies the URL::downloadTask pointer to a new “completed” list and then triggers an AsyncUpdate, so the pointer can be deleted from the “handleAsyncUpdate” function and that function then also adds another active download, so there is always four files downloading.

The problem is that the main-message thread is completely blocked if I download more than one file at a time. I can’t move the window and the GUI itself is not updated at all.

If I change the number to only one download at a time, the files download in the background, my GUI updates (the icons it downloads show up) and I can move the window around etc.

There is no-multi-threading stuff going on. The whole download queue class is essentially only two std::list and every time a callback for a finished file comes in, the next download is triggered.

The download DOES happen in the background (as it should), but somehow triggering multiple downloads blocks the main message thread completely.

Does anybody have any idea how that is possible? I looked at the source for URL::downloadToFile (Win32 version) and I can’t figure out what’s going on.

The files are being downloaded in handleAsyncUpdate? That function itself will run on the message thread

From handleAsyncUpdate:

No, the handleAsyncUpdate only triggers the next downloads. The function URL::downloadToFile is supposed to run in the background, but apparently it blocks during the “connect()” call, so I’m currently rewriting the whole downloader to even trigger the downloadToFile functions from a background thread, so nothing should get blocked.

1 Like

Yep, now it works as intended. Multi-threading is hard to get right.