StringReader.ReadToEndAsync メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
現在の位置から文字列の末尾まで、すべての文字を非同期的に読み取り、1 つの文字列として返します。
public:
override System::Threading::Tasks::Task<System::String ^> ^ ReadToEndAsync();
public override System.Threading.Tasks.Task<string> ReadToEndAsync();
[System.Runtime.InteropServices.ComVisible(false)]
public override System.Threading.Tasks.Task<string> ReadToEndAsync();
override this.ReadToEndAsync : unit -> System.Threading.Tasks.Task<string>
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.ReadToEndAsync : unit -> System.Threading.Tasks.Task<string>
Public Overrides Function ReadToEndAsync () As Task(Of String)
返品
非同期読み取り操作を表すタスク。
TResult パラメーターの値には、現在の位置から文字列の末尾までの文字を含む文字列が含まれています。
- 属性
例外
文字数が Int32.MaxValue より大きい。
文字列リーダーが破棄されました。
リーダーは現在、以前の読み取り操作で使用されています。
例
次の例は、文字列全体を非同期的に読み取る方法を示しています。
using System;
using System.IO;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
ReadCharacters();
}
static async void ReadCharacters()
{
StringBuilder stringToRead = new StringBuilder();
stringToRead.AppendLine("Characters in 1st line to read");
stringToRead.AppendLine("and 2nd line");
stringToRead.AppendLine("and the end");
using (StringReader reader = new StringReader(stringToRead.ToString()))
{
string readText = await reader.ReadToEndAsync();
Console.WriteLine(readText);
}
}
}
}
// The example displays the following output:
//
// Characters in 1st line to read
// and 2nd line
// and the end
//
Imports System.IO
Imports System.Text
Module Module1
Sub Main()
ReadCharacters()
End Sub
Async Sub ReadCharacters()
Dim stringToRead = New StringBuilder()
stringToRead.AppendLine("Characters in 1st line to read")
stringToRead.AppendLine("and 2nd line")
stringToRead.AppendLine("and the end")
Using reader As StringReader = New StringReader(stringToRead.ToString())
Dim readText As String = Await reader.ReadToEndAsync()
Console.WriteLine(readText)
End Using
End Sub
End Module
' The example displays the following output:
'
' Characters in 1st line to read
' and 2nd line
' and the end
'
注釈
このメソッドは、メソッドの同期的な例外がスローできるすべての非使用例外を返すタスクに格納します。 返されたタスクに例外が格納されている場合、その例外はタスクが待機しているときにスローされます。 ArgumentException などの使用に関する例外は、引き続き同期的にスローされます。 格納されている例外については、 ReadToEnd()によってスローされる例外を参照してください。