Back to Devexpress

AsyncDownloadPolicy.ConfigureHttpClient Event

corelibraries-devexpress-dot-data-dot-asyncdownloadpolicy-b8040921.md

latest4.4 KB
Original Source

AsyncDownloadPolicy.ConfigureHttpClient Event

Allows you to customize settings of a standard HttpClient component that DevExpress components use to download data (the default proxy, base address, cache size, and more).

Namespace : DevExpress.Data

Assembly : DevExpress.Data.v25.2.dll

NuGet Package : DevExpress.Data

Declaration

csharp
public static event AsyncDownloadPolicy.WeakEventHandler<AsyncDownloadPolicy.ConfigureHttpClientEventArgs> ConfigureHttpClient
vb
Public Shared Event ConfigureHttpClient As AsyncDownloadPolicy.WeakEventHandler(Of AsyncDownloadPolicy.ConfigureHttpClientEventArgs)

Event Data

The ConfigureHttpClient event's data class is AsyncDownloadPolicy.ConfigureHttpClientEventArgs. The following properties provide information specific to this event:

PropertyDescription
ClientGets an HttpClient component that DevExpress components use to download data.
ValueTypeGets a value that identifies the group of controls to which an individual control (that initiated the download) belongs. Inherited from AsyncDownloadPolicy.AsyncDownloaderEventArgs.

Remarks

For example, the default buffer size of an HttpClient is 2GB. WinForms PictureEdit controls reduce this size to 4096 bytes. If you attempt to download a larger image, you will get the “System.Net.Http.HttpRequestException: Cannot write more bytes to the buffer than the configured maximum buffer size: 4194304” exception. The following sample illustrates how to raise this limit to 16MB:

csharp
async void OnFormLoad(object sender, EventArgs e) {
    // Downloads a large image.
    await pictureEdit1.LoadAsync("...");
}
void OnConfigureHttpClient(object sender, ConfigureHttpClientEventArgs e) {
    e.Client.MaxResponseContentBufferSize = 1024*1024*16;
}
vb
Private Async Sub OnFormLoad(ByVal sender As Object, ByVal e As EventArgs)
    ' Downloads a large image.
    Await pictureEdit1.LoadAsync("...")
End Sub
Private Sub OnConfigureHttpClient(ByVal sender As Object, ByVal e As ConfigureHttpClientEventArgs)
    e.Client.MaxResponseContentBufferSize = 1024*1024*16
End Sub

You can also use DefaultResponseContentBufferSizeForHttpClient and DefaultBufferSizeForContentCopy settings to modify values for the static AsyncDownloadPolicy class constants and specify a global limit that can be changed within the ConfigureHttpClient event for individual UI controls.

csharp
DevExpress.Data.AsyncDownloadPolicy.DefaultResponseContentBufferSizeForHttpClient = 1024 * 1024 * 4; // 4MB
DevExpress.Data.AsyncDownloadPolicy.DefaulBufferSizeForContentCopy = 1024 * 16; // 16KB
vb
' 4MB
DevExpress.Data.AsyncDownloadPolicy.DefaultResponseContentBufferSizeForHttpClient = 1024 * 1024 * 4
' 16KB
DevExpress.Data.AsyncDownloadPolicy.DefaulBufferSizeForContentCopy = 1024 * 16

Read the following topic for detailed information and examples: Suppress Control Requests to Download Data from External URLs.

See Also

AsyncDownloadPolicy Class

AsyncDownloadPolicy Members

DevExpress.Data Namespace