共用方式為


WebClient.CancelAsync Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Cancels a pending asynchronous operation.

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)

Syntax

'Declaration
Public Sub CancelAsync
public void CancelAsync()

Exceptions

Exception Condition
OutOfMemoryException

There is not enough memory to continue the execution of the program.

StackOverflowException

The execution stack overflowed because it contains too many nested method calls.

ThreadAbortException

A call was made to the Thread.Abort method to destroy a thread.

Remarks

If an operation is pending, this method calls Abort on the underlying WebRequest.

When you call the CancelAsync method, your application still receives the completion event associated with the operation. For example, if you call CancelAsync to cancel a DownloadStringAsync operation and 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 of the AsyncCompletedEventArgs for the relevant completed event handler.

If you cancel a string download operation and you check the Result property of the

DownloadStringCompletedEventArgs object, an exception will occur.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.