.NET4.5 Async 与 Async Targeting Pack区别

Installation Instructions & Release Notes

The "Async Targeting Pack for Visual Studio 2012" enables projects targeting .NET Framework 4.0 or Silverlight 5 to use the Async language feature in C# 5 and Visual Basic 11. This pack requires Visual Studio 2012 and will not work with Visual Studio 2010.

The pack contains the API support necessary to use the 'async' and 'await' keywords in C# 5.0 and Visual Basic 11, as well as a set of Task-based adapter APIs that allow using some of the existing asynchronous APIs with the new language keywords.

This targeting pack is not required for projects targeting .NET Framework 4.5 or .NET for Metro style apps. It is only required for projects targeting Silverlight 5 and .NET Framework 4.0. Earlier platform releases are not supported.

License: http://go.microsoft.com/fwlink/?LinkId=248855.

More info on Task-based asynchronous programming in .NET: http://msdn.microsoft.com/async.

In this document:

  • Installation.
  • Release Notes.

Installation

The Async Targeting Pack for Visual Studio 2012 consists of a set of managed code assemblies that contain support types required by the C# and Visual Basic compilers integrated into Visual Studio 2012 and .NET 4.5 in order to support the 'async' and 'await' keywords, as well as some Task-based adapters for existing APIs. The pack is distributed via the NuGet package management system. One single NuGet package contains assemblies for all of the platforms supported by the Async Targeting Pack and the NuGet package manager will automatically ensure that your project references the correct assemblies.

If you are already familiar with NuGet:

The package ID of the Async Targeting Pack that you can use when searching for it is:
"Microsoft.CompilerServices.AsyncTargetingPack".

You can also visit the NuGet package information page for management console instructions.

If you are not yet very familiar with NuGet:

In order to familiarize yourself with the NuGet system, to learn how to enable it in your Visual Studio 2012 and how to install the Async Targeting Pack into your project, please read the following pages:

  • NuGet overview.
  • Installing NuGet into Visual Studio.
    Most flavours of Visual Studio 2012 already have NuGet pre-installed. If you version does not already have NuGet, follow this page to install it.
  • Managing NuGet packages.
    Learn here how to add the Async Targeting Pack to your Visual Studio project, and how to remove or update it.
    When searching for the Async Targeting Pack in the Manage NuGet Packages Dialog, use the following package ID: "Microsoft.CompilerServices.AsyncTargetingPack".
  • More NuGet documentation topics.

Release Notes

For each supported platform, two related, but distinct groups of functionality are included:

  1. Support types required by the Visual Studio 2012 C# and Visual Basic compilers to use the 'async' and 'await' keywords.
  2. Task-based adapter APIs that allow using some of the asynchronous APIs that exist in the targeted platform version with the new language keywords.

Both groups of functionality have some differences to the equivalent features in .NET 4.5, and .NET for Metro Style Apps. A non-exhaustive list of these differences includes:

.NET 4.5 / .NET for Metro Style Apps behavior Async Targeting Pack behavior
There are some new static convenience APIs on the Taskclass (e.g. Task.Run(..)). The new static convenience APIs are located on the TaskExclass (e.g. TaskEx.Run(..)).
.NET 4.5 has new, customized, more performant implementations for many Task-based asynchronous APIs. Many Task-based Async methods included in this Async Targeting Pack have the same signatures as new Task-based Async methods added in .NET 4.5. The functionality of these methods is generally intended to be equivalent, but it is not always identical. This is because the APIs in this Targeting Pack are usually thin Task-based adapters for functionality already available on the respective platform.
Changes made to the current ExecutionContext inside of an async method are undone prior to returning to the synchronous caller in an efficient manner. Changes made to the current ExecutionContext inside of an async method are not undone prior to returning to the synchronous caller and are thus visible to the caller.
When awaiting a cancelled Task returned from an asyncmethod, the same OperationCanceledException object that caused the Task to be cancelled is propagated out of awaiting on that Task. A new / different OperationCanceledException is thrown from the await.
When directly using TaskAwaiter*.UnsafeOnCompleted in .NET 4.5, the ExecutionContext is not flowed. The ExecutionContext is still flowed when using any of theUnsafeOnCompleted methods.
If an awaited Task completes on the "right"SynchronizationContext, its Continuation does not need to be posted back to the SynchronizationContext captured when the Task was started. Continuations are always posted to the capturedSynchronizationContext.
Visual Studio 2012 Debugger supports step-out for asyncmethods (via special methods on the Task class). Visual Studio 2012 Debugger does not support step-out forasync methods.
A number of pre-completed Task objects are cached for use by async methods of different return types. Fewer pre-completed Task objects are cached for use byasync methods.
When awaiting Task.Delay(.., CancellationToken) and if the returned Task completes as Canceled because theCancellationToken was canceled, theOperationCanceledException that gets thrown will have theCancellationToken stored in it. The CancellationToken is not stored in theOperationCanceledException.
Task.Run(..) uses the newTaskCreationsOptions.DenyChildAttach option. TaskEx.Run(..) does not use theTaskCreationsOptions.DenyChildAttach option, because it is not available.
If the Func<Task> delegate passed to the unwrapping overloads of Task.Run synchronously throws anOperationCanceledException, the returned Task gets cancelled. The returned Task gets faulted.

你可能感兴趣的:(.NET4.5 Async 与 Async Targeting Pack区别)