Skip to main content
All docs
V23.2

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.v23.2.dll

NuGet Package: DevExpress.Data

Declaration

public static event AsyncDownloadPolicy.WeakEventHandler<AsyncDownloadPolicy.ConfigureHttpClientEventArgs> ConfigureHttpClient

Event Data

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

Property Description
Client Gets an HttpClient component that DevExpress components use to download data.
ValueType Gets 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:

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;
}

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.

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

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

See Also