views:

386

answers:

5

Can anyone explain the "await" function?

+13  A: 

I can't

Eric Lippert can

Carlos Muñoz
+2  A: 

Is this what you are referring to?

Asynchronous Programming in C# 5.0 part two: Whence await?

Jordan
A: 

Actually this is not LINQ, this is the (only accounced) new feature in C#5, part of async programming.

As such, we don't really know too much about it.

However there's a decent writeup on it here.

RPM1984
+4  A: 

They just talked about this at PDC yesterday!

Await is used in conjunction with Tasks (parallel programming) in .NET. It's a keyword being introduced in the next version of .NET. It more or less lets you "pause" the execution of a method to wait for the Task to complete execution. Here's a brief example:

//create and run a new task  
Task<DataTable> dataTask = new Task<DataTable>(SomeCrazyDatabaseOperation);

//run some other code immediately after this task is started and running  
ShowLoaderControl();  
StartStoryboard();

//this will actually "pause" the code execution until the task completes.  It doesn't lock the thread, but rather waits for the result, similar to an async callback  
DataTable table = await dataTask;

//Now we can perform operations on the Task result, as if we're executing code after the async operation completed  
listBoxControl.DataContext = table;  
StopStoryboard();  
HideLoaderControl();
RTigger
When is it the C# form of promises: http://en.wikipedia.org/wiki/Futures_and_promises
Gorgen
Sounds a lot like Thread.Join().
Steve Guidi
Reminds me of [COMEFROM](http://en.wikipedia.org/wiki/COMEFROM)
Joel Spolsky
+2  A: 

Watch "The Future of C# and Visual Basic", Anders Hejlsberg's presentation at PDC 2010 where he covers this and gives some cool demos.

If you want to play around with it now, you can get the VS Async CTP here.

adrift