HttpListener.GetContextAsync HttpListener.GetContextAsync HttpListener.GetContextAsync HttpListener.GetContextAsync Method

定義

以非同步作業的方式,等候傳入要求。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 字串加入HttpListenerPrefixCollectionPrefixes屬性所傳回的。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.

適用於

另請參閱