How to do it...

  1. Create a large text file (we called ours taskFile.txt) and place it in a folder called C:\temp\taskFile\:
  1. In the AsyncDemo class, create a method called ReadBigFile() that returns a Task<TResult> type, which will be used to return an integer of bytes read from our big text file:
      public Task<int> ReadBigFile()       {           }
  1. Add the following code to open and read the file bytes. You will see that we are using the ReadAsync() method that asynchronously reads a sequence of bytes from the stream and advances the position of that stream by the number of bytes read from that stream. You will also notice that we are using a buffer ...

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.