This might be an issue of documentation. Your loop doesn't end until the transfer is complete, and I believe the handle may have been closed automatically at that time, so trying to re-close it fails. The help file does explicitly say to close the handle, but in the case of background download, maybe that doesn't apply after normal end of the transfer. You would still close the handle to cancel a transfer.