Method GetDeferral
GetDeferral()
Returns a deferral which can be completed when the event is ready to continue.
Declaration
public IDisposable GetDeferral()
Returns
Type | Description |
---|---|
System.IDisposable | A deferral object that implements System.IDisposable. |
Remarks
Sometimes, you may need to use async code when working with the
HttpResponseEnd event.
Normally, you might be able to use an async void
event
handler without issue.
Consider a scenario where you want to change the response received based on the contents of the current response. In order to do this, you need to asynchronously read the contents of the response before you can inspect it. In this scenario, an async event handler needs a way to delay the HTTP handler until it has completed processing the response.
The approach that WinRT has taken for this scenario is through "deferral" objects.
An asynchronous event handler acquires a deferral before the first
await
and notifies that deferral when the handler is complete.
Examples
The deferral should be combined with using
for convenient writing of async code.
ArcGISHttpClientHandler.HttpResponseEnd += async (sender, e) =>
{
using (e.GetDeferral())
{
// Your async code goes here...
var content = await e.Response.Content.ReadAsStringAsync().ConfigureAwait(false);
}
}
Applies to
Platforms and versions
Target | Versions |
---|---|
.NET Standard 2.0 | 100.10 - 200.5 |
.NET | 100.13 - 200.5 |
.NET Windows | 100.13 - 200.5 |
.NET Android | 200.0 - 200.5 |
.NET iOS | 200.0 - 200.5 |
.NET Framework | 100.10 - 200.5 |
Xamarin.Android | 100.10 - 100.15 |
Xamarin.iOS | 100.10 - 100.15 |
UWP | 100.10 - 200.5 |