HttpListener.BeginGetContext メソッド
アセンブリ: System (system.dll 内)

Public Function BeginGetContext ( _ callback As AsyncCallback, _ state As Object _ ) As IAsyncResult
Dim instance As HttpListener Dim callback As AsyncCallback Dim state As Object Dim returnValue As IAsyncResult returnValue = instance.BeginGetContext(callback, state)
戻り値
非同期操作のステータスを示す IAsyncResult オブジェクト。


BeginGetContext メソッドは、非同期 (非ブロック) の呼び出しを開始して、受信クライアント要求を受信します。このメソッドを呼び出す前に、Start メソッドを呼び出し、Prefixes プロパティから返される HttpListenerPrefixCollection に URI 文字列を追加して、待機する 1 つ以上の URI (Uniform Resource Identifier) プレフィックスを追加する必要があります。
非同期の操作は、EndGetContext メソッドを呼び出して終了させる必要があります。このメソッドは、通常、callback デリゲートによって呼び出されます。
このメソッドは、操作の実行中にブロックしません。受信要求を取得し、操作が完了するまでブロックするには、GetContext メソッドを呼び出します。
非同期プログラミング モデルの使用法の詳細については、「同期メソッドの非同期呼び出し」を参照してください。
呼び出し時の注意 このメンバは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。詳細については、「ネットワークのトレース」を参照してください。
BeginGetContext メソッドを使用して、受信クライアント要求を処理するコールバック メソッドを指定するコード例を次に示します。
public static void NonblockingListener(string [] prefixes) { HttpListener listener = new HttpListener(); foreach (string s in prefixes) { listener.Prefixes.Add(s); } listener.Start(); IAsyncResult result = listener.BeginGetContext(new AsyncCallback(ListenerCallback) ,listener); // Applications can do some work here while waiting for the // request. If no work can be done until you have processed a request , // use a wait handle to prevent this thread from terminating // while the asynchronous operation completes. Console.WriteLine("Waiting for request to be processed asyncronously."); result.AsyncWaitHandle.WaitOne(); Console.WriteLine("Request processed asyncronously."); listener.Close(); }
public static void ListenerCallback(IAsyncResult result) { HttpListener listener = (HttpListener) result.AsyncState; // Call EndGetContext to complete the asynchronous operation. HttpListenerContext context = listener.EndGetContext(result); HttpListenerRequest request = context.Request; // Obtain a response object. HttpListenerResponse response = context.Response; // Construct a response. string responseString = "<HTML><BODY> Hello world!</BODY></HTML>"; byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); // Get a response stream and write the response to it. response.ContentLength64 = buffer.Length; System.IO.Stream output = response.OutputStream; output.Write(buffer,0,buffer.Length); // You must close the output stream. output.Close(); }

Windows 98, Windows Server 2003, Windows XP Media Center Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からHttpListener.BeginGetContext メソッドを検索する場合は、下記のリンクをクリックしてください。

- HttpListener.BeginGetContext メソッドのページへのリンク