I want to call the asynchronous reader method of TextReader
, but always get a compile error:
var buffer = new char[10];
TextReader reader = new StreamReader(@"D:\temp\abc.txt");
// the following statement will get compile error
var readCount = await reader.ReadBlockAsync(buffer, 0, buffer.Length);
This is the error:
The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.
What is the right way to use ReadBlockAsync
?