1 / 21

Async made simple in Windows 8 with C# and Visual Basic

TOOL-810T. Async made simple in Windows 8 with C# and Visual Basic. Mads Torgersen and Alex Turner Program Managers Microsoft Corporation. The future is the future. .NET Async. Windows Runtime Async. Responsiveness and scalability Async is becoming the norm

cruz
Download Presentation

Async made simple in Windows 8 with C# and Visual Basic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TOOL-810T Async made simplein Windows 8with C# and Visual Basic Mads Torgersen and Alex Turner Program Managers Microsoft Corporation

  2. The future is the future • .NET Async • Windows Runtime Async • Responsiveness and scalability • Async is becoming the norm • Futures: Modern abstractions • Details: Different but similar

  3. Synchronous vs. asynchronous • var data = DownloadData(...); • ProcessData(data); STOP DownloadData ProcessData varfuture = DownloadDataAsync(...); future.ContinueWith(data => ProcessData(data)); DownloadDataAsync ProcessData

  4. Synchronous vs. asynchronous • var data = DownloadData(...); • ProcessData(data); STOP STOP DownloadData ProcessData varfuture = DownloadDataAsync(...); future.ContinueWith(data => ProcessData(data)); DownloadDataAsync ProcessData

  5. C# and Visual Basic let you do asynchronous programming without callbacks

  6. demo Using await with theWindows Runtime

  7. asyncmakes your method asynchronous

  8. awaitmakes the rest of your method a callback

  9. Awaitables IAsyncAction IAsyncOperation<TResult> • Returned from async Windows Runtime APIs • Must be started • awaitdirectly • StartAsTask and await later Task Task<TResult> • Returned from async C# and Visual Basic APIs • Already running • await directly • Store and awaitlater

  10. Task returning vs void returning async void Foo_Click(…); • Cannot be awaited • “Fire and forget” • Start separate independent flow • Use for event handlers • Use to override void methods async Task FooAsync(…); • Can be awaited • “Give back control” • Delegate asynchronous work • Use for helper methods • Use for library methods

  11. demo Coordinating Tasks

  12. Tasklets you coordinate activities

  13. Task helpers • Yielding control await Task.Delay(5000); await Task.Yield(); • Background running var result = await Task.Run(() => { … work … }); • Parallel composition • Task first = await Task.WhenAny(task1, task2); • varresults = await Task.WhenAll(task1, task2);

  14. demo Cancellation

  15. Cancellation and Progress • Pass CancellationToken to send cancellation • Pass IProgess to receive progress updates await FooAsync(…, cancel, progress); await FooAsync(…).StartAsTask(cancel, progress);

  16. No more callbacks!

  17. Related sessions • [TOOL-531T] Using the Windows Runtime from C# and Visual Basic • [PLAT-203T] Async everywhere: creating responsive APIs & apps • [TOOL-816T] Future directions for C# and Visual Basic • [SAC-804T] Building IIS and ASP.NET apps with the power of async --- • [TOOL-829T] The zen of async: Best practices for best performance

  18. Further reading and documentation • Async homepage: www.msdn.com/vstudio/async • What's New for Visual C#: http://msdn.com/en-us/library/hh156499(VS.110).aspx • What's New for Visual Basic:http://msdn.com/en-us/library/we86c8x2(VS.110).aspx

  19. thank you Feedback and questions http://forums.dev.windows.com Session feedbackhttp://bldw.in/SessionFeedback

  20. © 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

More Related