HttpListener.GetContextAsync 方法

定义

等待传入请求以作为异步操作。Waits for an incoming request as an asynchronous operation.

public:
 System::Threading::Tasks::Task<System::Net::HttpListenerContext ^> ^ GetContextAsync();
public System.Threading.Tasks.Task<System.Net.HttpListenerContext> GetContextAsync ();
member this.GetContextAsync : unit -> System.Threading.Tasks.Task<System.Net.HttpListenerContext>
Public Function GetContextAsync () As Task(Of HttpListenerContext)

返回

表示异步操作的任务对象。The task object representing the asynchronous operation. 任务对象上的 Result 属性将返回表示客户端请求的 HttpListenerContext 对象。The Result property on the task object returns an HttpListenerContext object that represents a client request.

注解

此操作不会阻止。This operation will not block. 收到传入请求后,将完成返回的 Task<TResult> 对象。The returned Task<TResult> object will complete when the incoming request has been received.

在调用此方法之前,必须调用 Start 方法,并添加至少一个要侦听的 URI 前缀,方法是将 URI 字符串添加到 Prefixes 属性返回的 HttpListenerPrefixCollection 中。Before calling this method, you must call the Start method and add at least one URI prefix to listen for by adding the URI strings to the HttpListenerPrefixCollection returned by the Prefixes property. 有关前缀的详细说明,请参阅 HttpListener 类概述。For a detailed description of prefixes, see the HttpListener class overview.

适用于

另请参阅