Your SlideShare is downloading. ×
Async CTP 3 Presentation for MUGH 2012
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Async CTP 3 Presentation for MUGH 2012

611
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
611
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. a tour ofAsynchronous Programming[Async CTP 3]
  • 2. srikanth@brainscale.com/vishwanath.srikanth@gmail.comVishwanath.srikanthVishsrikanthVishwanathsrikanth.wordpress.com Vishwanath Srikanth
  • 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. EARLIER WAYS OF PROGRAMMINGASYNC
  • 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. 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. Pre matured ways of async programming. What went wrong? • Disruptive Program Structure • Error prone • Heavy weight • Difficult to design and write
  • 8. New way of Async Programming DEMO
  • 9. Awaiting a AWAITING TASK ASYNCHRONOUSLY Task
  • 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. 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. ‘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. ‘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. Task basedProgramming TASK BASED ASYNC PATTERN
  • 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. 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. Consuming the Task Based Asynchronous Pattern • Continue Await using continuewith • Task.Yield() • Cancel Context - ConfigureAwait • Cancellation • Cancellation.None • Progress Reporting
  • 18. Building Task-Based CombinatorsTask.RunTask.WhenAll - Aggregate Exception or All Exceptions
  • 19. Building Task-Based Combinators Task.FromResult Task.WhenAny • Redundancy • Interleaving • Throttling • Early bailout
  • 20. Questions Thank you!
  • 21. There is more…. Goodies…… • Which namespace does Task belongs to ? • Can we utilize the power of multicore using Tasks?