[pollock] fix a sequential download issue

* Apparently you need to close the request/response as the Garbage Collection
  will not do that for you. High level language my ass!
This commit is contained in:
Pete Batard 2018-07-15 00:20:13 +01:00
parent d9d0feadb6
commit 1014b8008d
2 changed files with 13 additions and 11 deletions

View File

@ -114,7 +114,6 @@ namespace pollock
private static Encoding encoding = new UTF8Encoding(false); private static Encoding encoding = new UTF8Encoding(false);
private static List<string> rtl_languages = new List<string> { "ar-SA", "he-IL", "fa-IR" }; private static List<string> rtl_languages = new List<string> { "ar-SA", "he-IL", "fa-IR" };
private static Stopwatch sw = new System.Diagnostics.Stopwatch(); private static Stopwatch sw = new System.Diagnostics.Stopwatch();
private static WebClient wc = new WebClient();
private static DateTime last_changed = DateTime.MinValue; private static DateTime last_changed = DateTime.MinValue;
private static int download_status; private static int download_status;
private static int console_x_pos; private static int console_x_pos;
@ -726,12 +725,15 @@ namespace pollock
{ {
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); HttpWebResponse response = (HttpWebResponse)request.GetResponse();
status = response.StatusCode; status = response.StatusCode;
response.Close();
} }
catch (WebException we) catch (WebException we)
{ {
HttpWebResponse response = we.Response as HttpWebResponse; HttpWebResponse response = we.Response as HttpWebResponse;
status = response.StatusCode; status = response.StatusCode;
response.Close();
} }
request.Abort();
switch (status) switch (status)
{ {
case HttpStatusCode.OK: case HttpStatusCode.OK:
@ -754,7 +756,7 @@ namespace pollock
if (!ValidateDownload(url)) if (!ValidateDownload(url))
return null; return null;
using (wc) using (WebClient wc = new WebClient())
{ {
try try
{ {
@ -789,7 +791,7 @@ namespace pollock
return false; return false;
console_x_pos = Console.CursorLeft; console_x_pos = Console.CursorLeft;
using (wc) using (WebClient wc = new WebClient())
{ {
wc.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); wc.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
wc.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadCompleted); wc.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadCompleted);
@ -823,13 +825,13 @@ namespace pollock
{ {
if (cancel_requested) if (cancel_requested)
{ {
wc.CancelAsync(); ((WebClient)sender).CancelAsync();
return; return;
} }
if (in_progress)
return;
// Prevent this call from being re-entrant // Prevent this call from being re-entrant
if (in_progress)
return;
in_progress = true; in_progress = true;
speed = (e.BytesReceived / 1024d / sw.Elapsed.TotalSeconds); speed = (e.BytesReceived / 1024d / sw.Elapsed.TotalSeconds);

View File

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326 IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.2.1336" CAPTION "Rufus 3.2.1337"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0 FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -392,8 +392,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,2,1336,0 FILEVERSION 3,2,1337,0
PRODUCTVERSION 3,2,1336,0 PRODUCTVERSION 3,2,1337,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -411,13 +411,13 @@ BEGIN
VALUE "Comments", "https://akeo.ie" VALUE "Comments", "https://akeo.ie"
VALUE "CompanyName", "Akeo Consulting" VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.2.1336" VALUE "FileVersion", "3.2.1337"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html" VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus-3.2.exe" VALUE "OriginalFilename", "rufus-3.2.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.2.1336" VALUE "ProductVersion", "3.2.1337"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"