a tour ofAsynchronous Programming[Async CTP 3]
srikanth@brainscale.com/vishwanath.srikanth@gmail.comVishwanath.srikanthVishsrikanthVishwanathsrikanth.wordpress.com      ...
Topics for this Presentation Earlier ways    Awaiting Task            Task based   of Async     asynchronously           P...
EARLIER WAYS OF PROGRAMMINGASYNC
Async ProgrammingWhy do we need async?• Responsive UI.• Leverage Computing Power.• Better Utilization of Resources.• Bette...
Pre matured ways of async programming. Recommended Async Programming Concepts • Don’t wait for the response. • Return imme...
Pre matured ways of async programming. What went wrong? •   Disruptive Program Structure •   Error prone •   Heavy weight ...
New way of Async Programming DEMO
Awaiting a   AWAITING TASK ASYNCHRONOUSLY  Task
What is Async CTP?• A new language feature• New framework patternWhat do you need to start working onAsync CTP• Visual Stu...
Task and Task<T> •   A Task is a representation of ongoing work •   Available in .NET 4 •   Task returns nothing, Task<T> ...
‘async’ modifier • Indicates Asynchrony • Can be used for methods or Events or Methods or Lambdas • Out and ref are not al...
‘await’ keyword • Await - Prepend to a method which can return Task, Task<T> • Everything that continues is compiled async...
Task basedProgramming   TASK BASED ASYNC PATTERN
Task based async pattern                            Async                                UI Thread   Caller               ...
Task Based Asynchronous Pattern (TAP) • Task Behavior – Initialization, Exceptions, Target Environment, TaskStatus • Task ...
Consuming the Task Based Asynchronous Pattern • Continue Await using continuewith • Task.Yield() • Cancel Context - Config...
Building Task-Based CombinatorsTask.RunTask.WhenAll - Aggregate Exception or All Exceptions
Building Task-Based Combinators Task.FromResult Task.WhenAny  •   Redundancy  •   Interleaving  •   Throttling  •   Early ...
Questions            Thank you!
There is more…. Goodies…… • Which namespace does Task belongs to ? • Can we utilize the power of multicore using   Tasks?
Upcoming SlideShare
Loading in …5
×

Async CTP 3 Presentation for MUGH 2012

800 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
800
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Async CTP 3 Presentation for MUGH 2012

  1. 1. a tour ofAsynchronous Programming[Async CTP 3]
  2. 2. srikanth@brainscale.com/vishwanath.srikanth@gmail.comVishwanath.srikanthVishsrikanthVishwanathsrikanth.wordpress.com Vishwanath Srikanth
  3. 3. Topics for this Presentation Earlier ways Awaiting Task Task based of Async asynchronously Programming We have features for every step of the way
  4. 4. EARLIER WAYS OF PROGRAMMINGASYNC
  5. 5. Async ProgrammingWhy do we need async?• Responsive UI.• Leverage Computing Power.• Better Utilization of Resources.• Better user experience. What is expected from Async programming patterns? • Transparent Remote operations • Easy to code • Cancellations, Timeouts, Preserving threads during blocking awaits etc.
  6. 6. Pre matured ways of async programming. Recommended Async Programming Concepts • Don’t wait for the response. • Return immediately after issuing a async request • Let the response call you back. Earlier ways • IAsyncResult Pattern Ex: BeginRead, EndRead • Event based Asynchronous pattern Sync Async
  7. 7. Pre matured ways of async programming. What went wrong? • Disruptive Program Structure • Error prone • Heavy weight • Difficult to design and write
  8. 8. New way of Async Programming DEMO
  9. 9. Awaiting a AWAITING TASK ASYNCHRONOUSLY Task
  10. 10. What is Async CTP?• A new language feature• New framework patternWhat do you need to start working onAsync CTP• Visual Studio 2011 Beta• Visual Studio 2010 SP1 with Async CTPDownload from:http://www.microsoft.com/download/en/details.aspx?id=9983
  11. 11. Task and Task<T> • A Task is a representation of ongoing work • Available in .NET 4 • Task returns nothing, Task<T> returns a result of type T. • Normal tasks - Independent of Thread. • Async tasks run on same thread. • Propagate Exceptions
  12. 12. ‘async’ modifier • Indicates Asynchrony • Can be used for methods or Events or Methods or Lambdas • Out and ref are not allowed. • Analogous to ‘yield’
  13. 13. ‘await’ keyword • Await - Prepend to a method which can return Task, Task<T> • Everything that continues is compiled asynchronously • ‘Async’ Runs synchronously until first ‘await’.
  14. 14. Task basedProgramming TASK BASED ASYNC PATTERN
  15. 15. Task based async pattern Async UI Thread Caller Method Task/Task<T> Create Task & Check for callback Wait for ‘await’ Load the Context Capture Context continue Sign up a call back.
  16. 16. Task Based Asynchronous Pattern (TAP) • Task Behavior – Initialization, Exceptions, Target Environment, TaskStatus • Task States • Created, WaitingForActivation, WaitingToRun, Running, WaitingForChildrenToComplete, RanToCompletion, Canceled, Faulted. • Cancellation • Cancellations • Progress Reporting • Testable • TaskID • Task Creation Options – None, Prefairness, LongRunning, AttachedToParent
  17. 17. Consuming the Task Based Asynchronous Pattern • Continue Await using continuewith • Task.Yield() • Cancel Context - ConfigureAwait • Cancellation • Cancellation.None • Progress Reporting
  18. 18. Building Task-Based CombinatorsTask.RunTask.WhenAll - Aggregate Exception or All Exceptions
  19. 19. Building Task-Based Combinators Task.FromResult Task.WhenAny • Redundancy • Interleaving • Throttling • Early bailout
  20. 20. Questions Thank you!
  21. 21. There is more…. Goodies…… • Which namespace does Task belongs to ? • Can we utilize the power of multicore using Tasks?

×