DataReceivedEventArgs.Data プロパティ
アセンブリ: System (system.dll 内)


Process の StandardOutput または StandardError ストリームをイベント ハンドラにリダイレクトすると、プロセスがリダイレクトされたストリームに行を書き込むたびに、イベントが発生します。Data プロパティは、Process がリダイレクトされた出力ストリームに書き込んだ行です。イベント ハンドラは、Data プロパティを使用して、プロセス出力をフィルタ処理したり、出力を別の場所に書き込んだりできます。たとえば、エラー出力行をすべて指定されたエラー ログ ファイルに格納するイベント ハンドラを作成できます。
1 行は、末尾にライン フィード ("\n")、またはキャリッジ リターンとライン フィード ("\r\n") が付いた一連の文字として定義されています。改行文字は、既定のシステム ANSI コード ページを使用してエンコードされます。Data プロパティには、行の終端を示す復帰またはライン フィードは含まれません。
リダイレクトされたストリームを閉じると、null 行がイベント ハンドラに送られます。イベント ハンドラが Data プロパティを適切に検証してから、このプロパティにアクセスするようにしてください。たとえば、静的メソッド String.IsNullOrEmpty を使用して、イベント ハンドラで Data プロパティを検証できます。

OutputDataReceived イベントに関連付けられた単純なイベント ハンドラを示すコード例を次に示します。イベント ハンドラは、リダイレクトされた StandardOutput ストリームからテキスト行を受け取った後、そのテキストに書式を設定して画面に出力します。
Private Shared Sub SortOutputHandler(sendingProcess As Object, _ outLine As DataReceivedEventArgs) ' Collect the sort command output. If Not String.IsNullOrEmpty(outLine.Data) Then numOutputLines += 1 ' Add the text to the collected output. sortOutput.Append(Environment.NewLine + "[" _ + numOutputLines.ToString() + "] - " _ + outLine.Data) End If End Sub
private static void SortOutputHandler(object sendingProcess, DataReceivedEventArgs outLine) { // Collect the sort command output. if (!String.IsNullOrEmpty(outLine.Data)) { numOutputLines++; // Add the text to the collected output. sortOutput.Append(Environment.NewLine + "[" + numOutputLines.ToString() + "] - " + outLine.Data); } }
private: static void SortOutputHandler( Object^ /*sendingProcess*/ , DataReceivedEventArgs^ outLine ) { // Collect the sort command output. if ( !String::IsNullOrEmpty( outLine->Data ) ) { numOutputLines++; // Add the text to the collected output. sortOutput->AppendFormat( "\n[{0}] {1}", numOutputLines.ToString(), outLine->Data ); } }

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


Weblioに収録されているすべての辞書からDataReceivedEventArgs.Data プロパティを検索する場合は、下記のリンクをクリックしてください。

- DataReceivedEventArgs.Data プロパティのページへのリンク