From e90812a4a5c79f9d578bf502261ee55f19934037 Mon Sep 17 00:00:00 2001 From: "David R." Date: Thu, 30 Jan 2025 10:53:15 -0600 Subject: [PATCH] Added Timeout option in MyWebClient class for the WebRequest --- AutoUpdater.NET/AutoUpdater.cs | 8 +++++++- AutoUpdater.NET/MyWebClient.cs | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/AutoUpdater.NET/AutoUpdater.cs b/AutoUpdater.NET/AutoUpdater.cs index 480419c5..7f6c2818 100644 --- a/AutoUpdater.NET/AutoUpdater.cs +++ b/AutoUpdater.NET/AutoUpdater.cs @@ -245,6 +245,11 @@ public static class AutoUpdater /// public static Mode UpdateMode; + /// + /// Set the timeout in milliseconds for WebRequest of WebClient, default is 100000ms + /// + public static int Timeout = 100000; + /// /// An event that developers can use to exit the application gracefully. /// @@ -734,7 +739,8 @@ internal static MyWebClient GetWebClient(Uri uri, IAuthentication basicAuthentic { var webClient = new MyWebClient { - CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore) + CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore), + Timeout = AutoUpdater.Timeout }; if (Proxy != null) diff --git a/AutoUpdater.NET/MyWebClient.cs b/AutoUpdater.NET/MyWebClient.cs index 967d6a4e..95afae1f 100644 --- a/AutoUpdater.NET/MyWebClient.cs +++ b/AutoUpdater.NET/MyWebClient.cs @@ -11,6 +11,11 @@ public class MyWebClient : WebClient /// public Uri ResponseUri; + /// + /// Set Request timeout in milliseconds + /// + public int Timeout; + /// protected override WebResponse GetWebResponse(WebRequest request, IAsyncResult result) { @@ -18,4 +23,12 @@ protected override WebResponse GetWebResponse(WebRequest request, IAsyncResult r ResponseUri = webResponse.ResponseUri; return webResponse; } + + /// + protected override WebRequest GetWebRequest(Uri address) + { + WebRequest webRequest = base.GetWebRequest(address); + webRequest.Timeout = Timeout; + return webRequest; + } } \ No newline at end of file