There are some brand new asynchronous methods for file operation I/O, which are clearly designed for providing resource-intensive work without blocking the main UI thread.
For I/O operations, we have some interesting methods such as ReadAsync
, WriteAsync
, CopyToAsync
, FlushAsync
, ReadLineAsync
, and ReadToEndasync
, which are implemented on stream classes and on classes that read and/or write to streams such as TextWriter
or TextReader
.
Next we will see a simple example that we can extrapolate to a majority of these methods with ease.
Create a new Visual Studio project of type Console Application named
caAsyncIO
.Add a
using
clause forSystem.IO
:using System.IO;
Copy the following base method:
Private async static void CopyFolderContents() { String SourceFolder = @"C:\PACKT\02-CLR\caAsyncIO\source"; String DestinationFolder = @"C:\PACKT\02-CLR\caAsyncIO\destination"; Console.WriteLine("Going to copy {0} files..", Directory.EnumerateFiles...