3

I'm using URLDownloadToFile() to download update files for my game. The function is synchronous, so I have it running in a separate thread, and I use a IBindStatusCallback (specifically the onProgress() function) to handle the progress bar, and cancelling. It seems to be working great.

Right now I'm working on timeout mechanisms so that the download will cancel if it hangs. So, during testing I thought I'd interrupt the download by disconnecting my internet. When I do this, the download completely freezes, seemingly forever. URLDownloadToFile never returns. Worse, the IBindStatusCallback::onProgress() function doesn't ever get called again. This means I have no way of telling the process to cancel.

If the connection is restored, sometimes the download recovers, but other times it doesn't and just sits there forever.

This makes me think that I shouldn't even be using this technique in the first place, but it's just so simple and functional other than this issue. Is there a way around this problem?

I'm developing on Windows 7, and I have read while Googling that this issue may appear for some versions of Windows but not for others...

EDIT: Possibly worth mentioning is that this function is included in the URL Moniker set of Internet Explorer Platform APIs (in Urlmon.lib). It's possible that there is some separate function in the API or command that I could use to cancel the download or fix the problem another way.

Raptormeat
  • 312
  • 2
  • 14
  • 2
    Looks like a known issue: http://social.msdn.microsoft.com/Forums/en-US/73f1613b-fbff-48ea-a4d5-8423535d4fd8/urldownloadtofile-hangs-in-vista-but-not-in-xp-when-internet-connection-is-down?forum=vcgeneral – user1793036 Mar 26 '14 at 00:32
  • 1
    It all depends on how this function is implemented internally. If it uses synchronous WinINET API (which by all symptoms seems to be the case) then yes, you will have the problems. Recently I had to deal with the whole application written to use synchronous WinINET APIs to convert is to asynchronous. You will have to probably ditch this API and use a set of async WinINET functions. the async version works much better – cha Mar 26 '14 at 04:36

0 Answers0