Book Image

Microsoft .NET Framework 4.5 Quickstart Cookbook

By : Jose Luis Latorre
Book Image

Microsoft .NET Framework 4.5 Quickstart Cookbook

By: Jose Luis Latorre

Overview of this book

With about ten years since its first release, Microsoft's .NET Framework 4.5 is one of the most solid development technologies to create casual, business, or enterprise applications. It has evolved into a very stable framework and solid framework for developing applications, with a solid core, called the CLR (Common Language Runtime) Microsoft .NET Framework 4.5 includes massive changes and enables modern application and UI development."Microsoft .Net Framework 4.5 Quickstart Cookbook" aims to give you a run through the most exciting features of the latest version. You will experience all the flavors of .NET 4.5 hands on. The “How-to” recipes mix the right ingredients for a final taste of the most appetizing features and characteristics. The book is written in a way that enables you to dip in and out of the chapters.The book is full of practical code examples that are designed to clearly exemplify the different features and their applications in real-world development. All the chapters and recipes are progressive and based on the fresh features on .NET Framework 4.5.The book will begin by teaching you to build a modern UI application and improve it to make it Windows 8 Modern UI apps lifecycle model-compliant. You will create a portable library and throttle data source updating delays. Towards the end of the book, you will create you first Web API.
Table of Contents (19 chapters)
Microsoft .NET Framework 4.5 Quickstart Cookbook
About the Author
About the Reviewers

Using the new asynchronous file I/O operations

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.

How to do it...

Next we will see a simple example that we can extrapolate to a majority of these methods with ease.

  1. Create a new Visual Studio project of type Console Application named caAsyncIO.

  2. Add a using clause for System.IO:

    using System.IO;
  3. 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...