WebClient.OpenReadAsync 方法

定义

打开包含指定资源的可读流。Opens a readable stream containing the specified resource. 这些方法不阻止调用线程。These methods do not block the calling thread.

重载

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)

打开包含指定资源的可读流。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)

参数

address
Uri

要检索的资源的 URI。The URI of the resource to retrieve.

例外

address 参数为 nullThe address parameter is null.

通过组合 BaseAddress 和 address 所构成的 URI 无效。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.

注解

此方法检索 Stream 用于访问参数指定的资源的实例 addressThis 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. 若要在流可用时接收通知,请向事件添加事件处理程序 OpenReadCompletedTo receive notification when the stream is available, add an event handler to the OpenReadCompleted event.

备注

完成后,必须调用 Stream.Close Stream 以避免系统资源不足。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. 若要在等待流时阻止,请使用 OpenReadAsync 方法。To block while waiting for the stream, use the OpenReadAsync method.

在 .NET Framework 和 .NET Core 1.0 中,可以通过调用方法取消尚未完成的异步操作 CancelAsyncIn .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.

如果 BaseAddress 属性不是空字符串 ( "" ) 并且 address 未指定绝对 uri, address 则必须是与组合的相对 uri, BaseAddress 才能形成所请求资源的绝对 uri。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. 如果 QueryString 属性不为 null ,则将其追加到 addressIf the QueryString property is not null, it is appended to address.

此方法使用 RETR 命令下载 FTP 资源。This method uses the RETR command to download an FTP resource. 对于 HTTP 资源,使用 GET 方法。For an HTTP resource, the GET method is used.

备注

当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅 .NET Framework 中的网络跟踪For more information, see Network Tracing in .NET Framework.

适用于

OpenReadAsync(Uri, Object)

打开包含指定资源的可读流。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)

参数

address
Uri

要检索的资源的 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.

例外

address 参数为 nullThe address parameter is null.

通过组合 BaseAddress 和 address 所构成的 URI 无效。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.

注解

此方法检索 Stream 用于访问参数指定的资源的实例 addressThis 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. 若要在流可用时接收通知,请向事件添加事件处理程序 OpenReadCompletedTo receive notification when the stream is available, add an event handler to the OpenReadCompleted event.

备注

完成后,必须调用 Stream.Close Stream 以避免系统资源不足。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. 若要在等待流时阻止,请使用 OpenRead 方法。To block while waiting for the stream, use the OpenRead method.

在 .NET Framework 和 .NET Core 1.0 中,可以通过调用方法取消尚未完成的异步操作 CancelAsyncIn .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.

如果 BaseAddress 属性不是空字符串 ( "" ) 并且 address 未指定绝对 uri, address 则必须是与组合的相对 uri, BaseAddress 才能形成所请求资源的绝对 uri。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. 如果 QueryString 属性不为 null ,则将其追加到 addressIf the QueryString property is not null, it is appended to address.

此方法使用 RETR 命令下载 FTP 资源。This method uses the RETR command to download an FTP resource. 对于 HTTP 资源,使用 GET 方法。For an HTTP resource, the GET method is used.

备注

当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅 .NET Framework 中的网络跟踪For more information, see Network Tracing in .NET Framework.

适用于