Редагувати

Поділитися через


WebClient.OpenReadAsync Method

Definition

Opens a readable stream containing the specified resource. These methods do not block the calling thread.

Overloads

OpenReadAsync(Uri)

Opens a readable stream containing the specified resource. This method does not block the calling thread.

OpenReadAsync(Uri, Object)

Opens a readable stream containing the specified resource. This method does not block the calling thread.

OpenReadAsync(Uri)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

Opens a readable stream containing the specified resource. This method does not block the calling thread.

public:
 void OpenReadAsync(Uri ^ address);
public void OpenReadAsync (Uri address);
member this.OpenReadAsync : Uri -> unit
Public Sub OpenReadAsync (address As Uri)

Parameters

address
Uri

The URI of the resource to retrieve.

Exceptions

The address parameter is null.

The URI formed by combining BaseAddress and address is invalid.

-or-

An error occurred while downloading the resource.

-or-

An error occurred while opening the stream.

Remarks

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

This method retrieves a Stream instance used to access the resource specified by the address parameter. The stream is obtained using thread resources that are automatically allocated from the thread pool. To receive notification when the stream is available, add an event handler to the OpenReadCompleted event.

Note

You must call Stream.Close when you are finished with the Stream to avoid running out of system resources.

This method does not block the calling thread while the stream is opening. To block while waiting for the stream, use the OpenReadAsync method.

In .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.

If the BaseAddress property is not an empty string ("") and address does not specify an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested resource. If the QueryString property is not null, it is appended to address.

This method uses the RETR command to download an FTP resource. For an HTTP resource, the GET method is used.

Note

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in .NET Framework.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by OpenRead(Uri).

Applies to

OpenReadAsync(Uri, Object)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

Opens a readable stream containing the specified resource. This method does not block the calling thread.

public:
 void OpenReadAsync(Uri ^ address, System::Object ^ userToken);
public void OpenReadAsync (Uri address, object? userToken);
public void OpenReadAsync (Uri address, object userToken);
member this.OpenReadAsync : Uri * obj -> unit
Public Sub OpenReadAsync (address As Uri, userToken As Object)

Parameters

address
Uri

The URI of the resource to retrieve.

userToken
Object

A user-defined object that is passed to the method invoked when the asynchronous operation completes.

Exceptions

The address parameter is null.

The URI formed by combining BaseAddress and address is invalid.

-or-

An error occurred while downloading the resource.

-or-

An error occurred while opening the stream.

Remarks

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

This method retrieves a Stream instance used to access the resource specified by the address parameter. The stream is obtained using thread resources that are automatically allocated from the thread pool. To receive notification when the stream is available, add an event handler to the OpenReadCompleted event.

Note

You must call Stream.Close when you are finished with the Stream to avoid running out of system resources.

This method does not block the calling thread while the stream is opening. To block while waiting for the stream, use the OpenRead method.

In .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.

If the BaseAddress property is not an empty string ("") and address does not specify an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested resource. If the QueryString property is not null, it is appended to address.

This method uses the RETR command to download an FTP resource. For an HTTP resource, the GET method is used.

Note

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in .NET Framework.

Applies to