HttpListener.BeginGetContext メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpListener.BeginGetContext メソッドの意味・解説 

HttpListener.BeginGetContext メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

受信要求非同期取得開始します

名前空間: System.Net
アセンブリ: 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)
public IAsyncResult BeginGetContext (
    AsyncCallback callback,
    Object state
)
public:
IAsyncResult^ BeginGetContext (
    AsyncCallback^ callback, 
    Object^ state
)
public IAsyncResult BeginGetContext (
    AsyncCallback callback, 
    Object state
)
public function BeginGetContext (
    callback : AsyncCallback, 
    state : Object
) : IAsyncResult

パラメータ

callback

クライアント要求使用可能なときに呼び出すメソッド参照する AsyncCallback デリゲート

state

操作に関する情報格納するユーザー定義のオブジェクト。このオブジェクトは、操作完了時に callback デリゲート渡されます。

戻り値
非同期操作ステータスを示す IAsyncResult オブジェクト

例外例外
解説解説
使用例使用例

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();
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からHttpListener.BeginGetContext メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHttpListener.BeginGetContext メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHttpListener.BeginGetContext メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

HttpListener.BeginGetContext メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HttpListener.BeginGetContext メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS