Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading content…
Transcript

Ooops, it's an advert ....

IMC Group

I'm no Jon Skeet ...

VB v.Next

C# 5

Compiler as a service

Asynchronous programming

Async CTP

Installs to My Documents

Based on .NET 4 so

some compromises

Since the CTP installs on top of .NET 4, it is not possible for the CTP to add new members to existing types. While instance members are mimicked by extension methods, there is no way to add static members such as Task.Run. Instead these are offered on a “temporary” type called TaskEx.

NOT compatible with MVC3

or VS2010 SP1

Async CTP

With web based services,

including provisioning in the

cloud asynchronous operations

are becoming the norm rather

than an exception.

CTP attempts to improve the

handling of asynchronous

operations

'async is about managing complexity, not hiding it',

Jon Skeet

async

the async keyword indicates to the compiler

that the method decorated with async is likely

to include awaits wtihin the method body

async keyword on a method

is a statement of intent

Eric Lippert

The “async” modifier on the method does not mean “this method is automatically scheduled to run on a worker thread asynchronously”. It means the opposite of that; it means “this method contains control flow that involves awaiting asynchronous operations and will therefore be rewritten by the compiler into continuation passing style to ensure that the asynchronous operations can resume this method at the right spot.” The whole point of async methods it that you stay on the current thread as much as possible. They’re like coroutines: async methods bring single-threaded cooperative multitasking to C#.

http://blogs.msdn.com/b/ericlippert/archive/2010/10/29/asynchronous-programming-in-c-5-0-part-two-whence-await.aspx

an async method returns

void, Task or Task<T>

await

other keywords considered -

'wait for', 'yield with', 'yield'

await signs up the rest of the method as a continuation of the task and returns to the caller

Eric Lippert

If the “await” operator is used twice in a method this does not mean “this method now blocks the current thread until the asynchronous operation returns”. That would be making the asynchronous operation back into a synchronous operation, which is precisely what we are attempting to avoid. Rather, it means the opposite of that; it means “if the task we are awaiting has not yet completed then sign up the rest of this method as the continuation of that task, and then return to your caller immediately; the task will invoke the continuation when it completes.”

http://blogs.msdn.com/b/ericlippert/archive/2010/10/29/asynchronous-programming-in-c-5-0-part-two-whence-await.aspx

like iterators the await is effectively creating a state machine for you

But I thought that

this whole async thing was about multithreading?

Time for a cup of tea or coffee ....

So quite often there will only be a single thread switching between tasks.

Task<T>

Task<T> has the ability to 'return' a value from an awaited asynchronous operation

Eric Lippert ... discussing async and the await keyword ...

For now, let's provisionally call this new feature TAP, the Task Asynchrony Pattern. I'm sure we'll come up with a better name later; remember, this is still just a prototype. (*)

Similarly with TAP: any type that has a GetAwaiter that returns a type that has BeginAwait, EndAwait, and so on, can be used in "await" expressions. However, methods marked as being async can only return void, Task, or Task<T> for some T.

http://blogs.msdn.com/b/ericlippert/archive/2010/11/01/asynchrony-in-c-5-part-three-composition.aspx

(*) I emphasize that this is provisional and for my own rhetorical purposes, and not an official name of anything. Please don't publish a book called "Essential TAP" or "Learn TAP in 21 Time Units" or whatever. I have a copy of "Instant DHTML Scriptlets" on my bookshelf; Dino Esposito writes so fast that he published an entire book between the time we mentioned the code name of the product to him and we announced the real name. ("Windows Script Components" was the final name.)

a 'promise' or 'future' - something that will deliver a value of T in the future

Liam Westley

liam.westley@tigernews.co.uk

http://geekswithblogs.net/twickers

... more a Tony the Pony

Greg Duncan

http://coolthingoftheday.blogspot.com/2010/10/pdc10-async-round-up.html

Eric Lippert

http://blogs.msdn.com/b/ericlippert/

Jon Skeet

http://msmvps.com/blogs/jon_skeet/default.aspx

Learn more about creating dynamic, engaging presentations with Prezi