corelibraries-devexpress-dot-data-dot-asyncdownloadpolicy-112ec451.md
Occurs if an external resource fails to load.
Namespace : DevExpress.Data
Assembly : DevExpress.Data.v25.2.dll
NuGet Package : DevExpress.Data
public static event AsyncDownloadPolicy.WeakEventHandler<AsyncDownloadPolicy.FailedEventArgs> Failed
Public Shared Event Failed As AsyncDownloadPolicy.WeakEventHandler(Of AsyncDownloadPolicy.FailedEventArgs)
The Failed event's data class is AsyncDownloadPolicy.FailedEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Content | Gets or sets the content in place of an external resource that fails to load. |
| ErrorContent | |
| Exception | Gets the exception. |
| Uri | Gets the identifier of the downloaded resource. |
| ValueType | Gets a value that identifies the group of controls to which an individual control (that initiated the download) belongs. Inherited from AsyncDownloadPolicy.AsyncDownloaderEventArgs. |
The event data class exposes the following methods:
| Method | Description |
|---|---|
| Throw() | Throws the exception. |
Handle the Failed event to supply the content instead of the resource that could not be loaded or throw an exception.
Use the e.Content event parameter to specify the content instead of an external resource that fails to load. Call the e.Throw() method to throw an exception.
The following example handles the Failed event to display a placeholder image in a WinForms PictureEdit if an external image fails to load:
public Form1() {
InitializeComponent();
DevExpress.Data.AsyncDownloadPolicy.Failed += AsyncDownloadPolicy_Failed;
}
void AsyncDownloadPolicy_Failed(object sender, DevExpress.Data.AsyncDownloadPolicy.FailedEventArgs e) {
if (e.ValueType.Name == "ImageOrSvgImageResult") {
MemoryStream stream = new MemoryStream();
/* A placeholder image is obtained from the DevExpress SvgImageCollection.
* The placeholder image was added to the SvgImageCollection at design time.
*/
var errorImage = svgImageCollection1[0];
errorImage.Save(stream);
e.Content = stream;
}
}
async void btnLoadImage_Click(object sender, EventArgs e) {
await pictureEdit1.LoadAsync("EXTERNAL_IMAGE_URL");
}
Public Sub New()
InitializeComponent()
DevExpress.Data.AsyncDownloadPolicy.Failed += AsyncDownloadPolicy_Failed
End Sub
Private Sub AsyncDownloadPolicy_Failed(ByVal sender As Object, ByVal e As DevExpress.Data.AsyncDownloadPolicy.FailedEventArgs)
If e.ValueType.Name = "ImageOrSvgImageResult" Then
Dim stream As New MemoryStream()
Dim errorImage = svgImageCollection1(0)
errorImage.Save(stream)
e.Content = stream
End If
End Sub
Async Sub btnLoadImage_Click(ByVal sender As Object, ByVal e As EventArgs)
Await pictureEdit1.LoadAsync("EXTERNAL_IMAGE_URL")
End Sub
Read the following topic for additional information: Suppress Control Requests to Download Data from External URLs.
See Also