O'Reilly logo

C# 7 and .NET Core Cookbook by Dirk Strauss

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required