public virtual System.Threading.Tasks.ValueTask<int> ReadAsync (Memory<byte> buffer, System.Threading.CancellationToken cancellationToken = default);
abstract member ReadAsync : Memory<byte> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<int>
override this.ReadAsync : Memory<byte> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<int>
Public Overridable Function ReadAsync (buffer As Memory(Of Byte), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Integer)
方法
ReadAsync
使你能够在不阻塞主线程的情况下执行资源密集型 I/O 操作。 在 Windows 8.x 应用商店应用或桌面应用中一个耗时的流操作可能阻塞 UI 线程并让应用看起来好像不工作时,这种性能的考虑就显得尤为重要了。 异步方法与
async
Visual Basic 和 C# 中的 和
await
关键字结合使用。
CanRead
使用 属性确定当前实例是否支持读取。
如果在操作完成之前取消,则返回的任务将
TaskStatus.Canceled
包含 属性的值
Status
。
有关示例,请参阅
ReadAsync(Byte[], Int32, Int32)
重载。
public:
System::Threading::Tasks::Task<int> ^ ReadAsync(cli::array <System::Byte> ^ buffer, int offset, int count);
public System.Threading.Tasks.Task<int> ReadAsync (byte[] buffer, int offset, int count);
[System.Runtime.InteropServices.ComVisible(false)]
public System.Threading.Tasks.Task<int> ReadAsync (byte[] buffer, int offset, int count);
member this.ReadAsync : byte[] * int * int -> System.Threading.Tasks.Task<int>
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.ReadAsync : byte[] * int * int -> System.Threading.Tasks.Task<int>
Public Function ReadAsync (buffer As Byte(), offset As Integer, count As Integer) As Task(Of Integer)
private async void Button_Click(object sender, RoutedEventArgs e)
string filename = @"c:\Temp\userinputlog.txt";
byte[] result;
using (FileStream SourceStream = File.Open(filename, FileMode.Open))
result = new byte[SourceStream.Length];
await SourceStream.ReadAsync(result, 0, (int)SourceStream.Length);
UserInput.Text = System.Text.Encoding.ASCII.GetString(result);
Imports System.IO
Imports System.Text
Class MainWindow
Private Async Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim filename As String = "c:\Temp\userinputlog.txt"
Dim result As Byte()
Using SourceStream As FileStream = File.Open(filename, FileMode.Open)
result = New Byte(SourceStream.Length - 1) {}
Await SourceStream.ReadAsync(result, 0, CType(SourceStream.Length, Integer))
End Using
UserInput.Text = System.Text.Encoding.ASCII.GetString(result)
End Sub
End Class
方法
ReadAsync
使你能够在不阻塞主线程的情况下执行资源密集型 I/O 操作。 在 Windows 8.x 应用商店应用或桌面应用中一个耗时的流操作可能阻塞 UI 线程并让应用看起来好像不工作时,这种性能的考虑就显得尤为重要了。 异步方法与
async
Visual Basic 和 C# 中的 和
await
关键字结合使用。
CanRead
使用 属性确定当前实例是否支持读取。
public:
virtual System::Threading::Tasks::Task<int> ^ ReadAsync(cli::array <System::Byte> ^ buffer, int offset, int count, System::Threading::CancellationToken cancellationToken);
public virtual System.Threading.Tasks.Task<int> ReadAsync (byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken);
[System.Runtime.InteropServices.ComVisible(false)]
public virtual System.Threading.Tasks.Task<int> ReadAsync (byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken);
abstract member ReadAsync : byte[] * int * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
override this.ReadAsync : byte[] * int * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member ReadAsync : byte[] * int * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
override this.ReadAsync : byte[] * int * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
Public Overridable Function ReadAsync (buffer As Byte(), offset As Integer, count As Integer, cancellationToken As CancellationToken) As Task(Of Integer)
方法
ReadAsync
使你能够在不阻塞主线程的情况下执行资源密集型 I/O 操作。 在 Windows 8.x 应用商店应用或桌面应用中一个耗时的流操作可能阻塞 UI 线程并让应用看起来好像不工作时,这种性能的考虑就显得尤为重要了。 异步方法与
async
Visual Basic 和 C# 中的 和
await
关键字结合使用。
CanRead
使用 属性确定当前实例是否支持读取。
如果在操作完成之前取消,则返回的任务将
Canceled
包含 属性的值
Status
。
有关示例,请参阅
ReadAsync(Byte[], Int32, Int32)
重载。