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

Public Overrides Function BeginWrite ( _ buffer As Byte(), _ offset As Integer, _ size As Integer, _ callback As AsyncCallback, _ state As Object _ ) As IAsyncResult
Dim instance As NetworkStream Dim buffer As Byte() Dim offset As Integer Dim size As Integer Dim callback As AsyncCallback Dim state As Object Dim returnValue As IAsyncResult returnValue = instance.BeginWrite(buffer, offset, size, callback, state)
public override IAsyncResult BeginWrite ( byte[] buffer, int offset, int size, AsyncCallback callback, Object state )
public: virtual IAsyncResult^ BeginWrite ( array<unsigned char>^ buffer, int offset, int size, AsyncCallback^ callback, Object^ state ) override
public IAsyncResult BeginWrite ( byte[] buffer, int offset, int size, AsyncCallback callback, Object state )
public override function BeginWrite ( buffer : byte[], offset : int, size : int, callback : AsyncCallback, state : Object ) : IAsyncResult
戻り値
非同期呼び出しを表す IAsyncResult。


BeginWrite メソッドは、リモート ホストへの非同期送信操作を開始します。BeginWrite メソッドを呼び出すと、個別の実行スレッド内でデータを送信できます。
AsyncCallback デリゲートを実装するコールバック メソッドを作成し、その名前を BeginWrite メソッドに渡す必要があります。使用する state パラメータは、少なくとも NetworkStream を格納している必要があります。他の情報がコールバックに必要な場合は、小さなクラスまたは構造体を作成して NetworkStream などの必要な情報を保持します。構造体またはクラスのインスタンスは、state パラメータを使用して BeginWrite メソッドに渡します。
コールバック メソッドは EndWrite メソッドを実装する必要があります。アプリケーションが BeginWrite を呼び出すと、指定したコールバック メソッドが個別のスレッドを使用して実行され、EndWrite は、NetworkStream が要求されたバイト数を送信するか例外をスローするまでブロックします。BeginWrite メソッドを呼び出してから元のスレッドをブロックする場合は、WaitOne メソッドを使用します。元のスレッドの実行を継続させるには、コールバック メソッドで Set を呼び出します。コールバック メソッドの記述に関する追加情報については、「Callback のサンプル」を参照してください。
![]() |
---|
IOException が発生した場合は、InnerException プロパティをチェックして、この原因が SocketException かどうかを確認してください。その場合、ErrorCode プロパティを使用して特定のエラー コードを取得してください。エラーの詳細については、MSDN で Windows Socket Version 2 API のエラー コードのドキュメントを参照してください。 |

BeginWrite を使用して、ネットワーク ストリームに非同期的にデータを書き込むコード例を次に示します。myWriteCallBack メソッドは AsyncCallback デリゲートを実装しており、BeginWrite の終了時に呼び出されます。
' Check to see if this NetworkStream is writable. If myNetworkStream.CanWrite Then Dim myWriteBuffer As Byte() = Encoding.ASCII.GetBytes("Are you receiving this message?") myNetworkStream.BeginWrite(myWriteBuffer, 0, myWriteBuffer.Length, New AsyncCallback(AddressOf NetworkStream_ASync_Send_Receive.myWriteCallBack), myNetworkStream) allDone.WaitOne() Else Console.WriteLine("Sorry. You cannot write to this NetworkStream.") End If
// Check to see if this NetworkStream is writable. if (myNetworkStream.CanWrite){ byte[] myWriteBuffer = Encoding.ASCII.GetBytes("Are you receiving this message?"); myNetworkStream.BeginWrite(myWriteBuffer, 0, myWriteBuffer.Length, new AsyncCallback(NetworkStream_ASync_Send_Receive.myWriteCallBack), myNetworkStream); allDone.WaitOne(); } else{ Console.WriteLine("Sorry. You cannot write to this NetworkStream."); }
// Check to see if this NetworkStream is writable. if ( myNetworkStream->CanWrite ) { array<Byte>^myWriteBuffer = Encoding::ASCII->GetBytes( "Are you receiving this message?" ); myNetworkStream->BeginWrite( myWriteBuffer, 0, myWriteBuffer->Length, gcnew AsyncCallback( &MyNetworkStreamClass::myWriteCallBack ), myNetworkStream ); allDone->WaitOne(); } else { Console::WriteLine( "Sorry. You cannot write to this NetworkStream." ); }
// Check to see if this NetworkStream is writable. if (myNetworkStream.get_CanWrite()) { ubyte myWriteBuffer[] = Encoding.get_ASCII(). GetBytes("Are you receiving this message?"); myNetworkStream.BeginWrite(myWriteBuffer, 0, myWriteBuffer.get_Length(), new AsyncCallback(NetworkStreamASyncSendReceive. MyWriteCallBack), myNetworkStream); allDone.WaitOne(); } else { Console.WriteLine("Sorry. You cannot write to this " + "NetworkStream."); }

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


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

- NetworkStream.BeginWrite メソッドのページへのリンク