Skip to content

Added Timeout option in MyWebClient class for the WebRequest #726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion AutoUpdater.NET/AutoUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ public static class AutoUpdater
/// </summary>
public static Mode UpdateMode;

/// <summary>
/// Set the timeout in milliseconds for WebRequest of WebClient, default is 100000ms
/// </summary>
public static int Timeout = 100000;

/// <summary>
/// An event that developers can use to exit the application gracefully.
/// </summary>
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions AutoUpdater.NET/MyWebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,24 @@ public class MyWebClient : WebClient
/// </summary>
public Uri ResponseUri;

/// <summary>
/// Set Request timeout in milliseconds
/// </summary>
public int Timeout;

/// <inheritdoc />
protected override WebResponse GetWebResponse(WebRequest request, IAsyncResult result)
{
WebResponse webResponse = base.GetWebResponse(request, result);
ResponseUri = webResponse.ResponseUri;
return webResponse;
}

/// <inheritdoc />
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest webRequest = base.GetWebRequest(address);
webRequest.Timeout = Timeout;
return webRequest;
}
}