Agafonov Slava Digest about software

Visual Studio Async

Asynchronous operations are methods and other function members that may have most of their execution take place after they return. In .NET the recommended pattern for asynchronous operations is for them to return a task which represents the ongoing operation and allows waiting for its eventual outcome. An asynchronous function is a method or anonymous function which is marked with the async modifier. A function without the async modifier is called synchronous. You would experience the following behavior using a synchronous application. The program becomes non-responsive. You cannot move, resize the window while data is loading. You cannot hit the Close button to end the program while data is loading.

Why asynchronous?

For decades programming with remote resources has presented a conundrum. As the level of abstraction in “local” programming has been steadily rising, there has been a push for transparency of remote operations – they should look just like local ones, so that a developer doesn’t need to grapple with conceptual overhead, architectural impedance mismatch and leaky abstractions.


The problem is that remote operations are different from local ones. They have orders of magnitude more latency even at the best of times may fail in new ways or simply never come back, depend on a variety of external factors beyond the developer’s control or even perception, etc. So while they can be represented like “just method calls,” it is not desirable to do so because the developer is left without handles to manage the special conditions arising from their remoteness – managing cancellation and timeouts, preserving threading resources during blocking waits, predicting and handling threats to responsiveness, etc.


On .NET we have not ignored this challenge. In fact we have not just one but several patterns for how to do asynchronous programming; that is, dealing with I/O and similar high latency operations without blocking threads. Most often there is both a synchronous (i.e. blocking transparently) and an asynchronous (i.e. latency-explicit) way of doing things. The problem is that these current patterns are very disruptive to program structure, leading to exceedingly complex and error prone code or (more commonly) developers giving up and using the blocking approach, taking a responsiveness and performance hit instead.


The goal should be to bring the asynchronous development (
Visual Studio Async) experience as close to the synchronous paradigm as possible, without letting go of the ability to handle the asynchrony-specific situations. Asynchrony should be explicit and non-transparent, but in a very lightweight and non-disruptive manner. Compensability, abstraction and control structures should all work as simply and intuitively as with synchronous code.

Visual Studio Async

The main point of Visual Studio Async is to simplify asynchronous programming. If you have ever wrote some asynchronous code you know very well that it is more complex than synchronous code. And it is also longer. Instead of calling simple method using one line we have to write method that initializes asynchronous call and then we have to write callback that is called when asynchronous code has completed the work it got to do.

Smarter ones of you have also thought many times that there should be some patterns because what we are doing when writing asynchronous code that solves different problems has still some similarities. Slowly, step by step, we are now getting to the point where complexities of asynchronous code are solved by compiler and we can write asynchronous code almost like synchronous one.

Mads Torgersen, C# specification lead, describes the new C# features to improve asynchronous development.

Get Microsoft Silverlight

Anders Hejlsberg: Introducing Async – Simplifying Asynchronous Programming

Visual Studio Async Get Microsoft Silverlight

For implementing asynchonous functionlity (Visual Studio Async) and cancelation tokens we will need to add assebmly, for example Silverlight assemblies with names: AsyncCtpLibrary.dll and AsyncCtpLibrary_Silverlight.dll.

Visual Studio Async

References

Visual Studio Async CTP

Asynchronous Programming for C#

C# Language Specification for Asynchronous Functions

Whitepaper: Asynchrony in .NET

Making Asynchronous Programming Easy

(CSharp Spec) Asynchronous Functions.docx (48.56 kb)

(Whitepaper) Asynchrony in .NET.docx (56.47 kb)

Visual Studio Async

Summary

Async CTP introduces a new keyword await, which indicates that the caller would like control to return when an asynchronous method call has completed. This word is just like #define keyword or code snippet for asynchonous programming that is using delegates and Test Parallel Library multitheading. Extension method make asynchonous results that can be used asynchonously. We can get resulst asynchronously from asynchronous method. Note that async is a contextual keyword. In all syntactic contexts other than the ones above it is considered an identifier.

using async = System.Threading.Tasks.Task;

async async async(async async) { }

The Visual Studio Async CTP combines a new simple and composable pattern for asynchronous APIs, with "await" and "async" language keywords in Visual Basic and C#, that avoids asynchronous code having to be written "inside-out" using callbacks. The CTP is a painless install/uninstall on top of Visual Studio 2010 RTM, and comes with plenty of samples and documentation.  The single AsyncCtpLibrary assembly is just 104Kb, and the Silverlight version only 132Kb.  Recommended, because it's pretty likely you'll see this in C# 5. Multiple logical flow are really simple to implement now. No extra threads running, but you can implement them customly.


Requirements - to install and use Visual Studio Async your technical environment must meet the following requirements to operating system and Visual Studio:

  • Operating system: Windows 7, Windows Server 2003, Windows Server 2008, Windows Vista, or Windows XP
  • Visual Studio: Professional, Premium, or Ultimate (English-US version)

 

Visual Studio Asyncnchonous

Comments (1) -

  • Agafonov

    11/16/2010 10:16:38 PM | Reply

    Do you like new release of Visual Studio? What about feature Visual Studio Async?

Add comment

Loading

Copyright © 2018 - Design by FS