WebClient.CancelAsync Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Cancels a pending asynchronous operation.
public:
void CancelAsync();
public void CancelAsync ();
member this.CancelAsync : unit -> unit
Public Sub CancelAsync ()
Forsiktig
WebRequest
, HttpWebRequest
, ServicePoint
, and WebClient
are obsolete, and you shouldn't use them for new development. Use HttpClient instead.
If an operation is pending, this method calls Abort on the underlying WebRequest.
Obs!
Starting in .NET Core 2.0, CancelAsync doesn't cancel the request immediately if the response has started to fetch. For optimum cancellation behavior, use the HttpClient class instead of WebClient.
When you call CancelAsync, your application still receives the completion event associated with the operation. For example, when you call CancelAsync to cancel a DownloadStringAsync operation, if you have specified an event handler for the DownloadStringCompleted event, your event handler receives notification that the operation has ended. To learn whether the operation completed successfully, check the Cancelled property on the base class of DownloadDataCompletedEventArgs in the event data object passed to the event handler.
If no asynchronous operation is in progress, this method does nothing.
Produkt | Versjoner |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET-tilbakemelding
.NET er et åpen kilde-prosjekt. Velg en kobling for å gi tilbakemelding: