Can anyone explain the "await" function?
+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
2010-10-30 05:30:08
When is it the C# form of promises: http://en.wikipedia.org/wiki/Futures_and_promises
Gorgen
2010-10-30 06:07:56
Sounds a lot like Thread.Join().
Steve Guidi
2010-10-30 15:34:15
Reminds me of [COMEFROM](http://en.wikipedia.org/wiki/COMEFROM)
Joel Spolsky
2010-10-31 13:27:39