CSharp 5 Async

550 views
483 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
550
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
21
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

CSharp 5 Async

  1. 1. www.dotnet.lv
  2. 2. Valdis IljuconoksTechnical Fellow, Software ArchitectMicrosoft MVP Geta AS, Viiar Consulting valdis.iljuconoks@dotnet.lv http://dotnet.lv/blogs/vi @tech_fellow
  3. 3. C#
  4. 4. 5.0
  5. 5. Async
  6. 6. concurrency & asynchrony
  7. 7. sequential concurrent parallelasynchronous
  8. 8. agenda predecessorsawaiting tasks
  9. 9. predecessors
  10. 10. Asynchronous Programming Model (APM)Event-based Asynchronous Pattern (EAP)
  11. 11. C# 5.0 C# 4.0 Async C# 3.0 Dynamics Language C# 2.0 Integrated Generics QueryC# 1.0Componenton aManagedRuntime
  12. 12. awaiting tasks
  13. 13. ‘Task’ is representation of ongoing work
  14. 14. varvar
  15. 15. async / await
  16. 16. similar to synchronous code
  17. 17. referred as async method
  18. 18. modifier (async) applied to• a method• a lambda expression• an anonymous method
  19. 19. keyword (await) used in• body of an immediately enclosing method• lambda expression• anonymous method
  20. 20. await NOT used in• synchronous function• query expression• catch or finally block• in lock statement• unsafe context
  21. 21. absence of an operatorcause a compiler warning
  22. 22. characteristics
  23. 23. Async methods are intended to be non- blocking operations
  24. 24. await expression does not block the current thread while the awaited task is running
  25. 25. expression signs up the rest of the method as a continuation
  26. 26. and
  27. 27. returns control to the caller of the async method.
  28. 28. Method executes synchronously till first ‘await’.
  29. 29. Async methods dont require multithreading
  30. 30. async method doesnt run on its own thread
  31. 31. method runs on the current synchronization context.
  32. 32. Task based async pattern
  33. 33. Async method return types• void• Task• Task<TResult>
  34. 34. async void FireAndForget(){ await t;}FireAndForget();
  35. 35. async Task JustSignalCompletionAsync(){ return;}await JustSignalCompletionAsync();
  36. 36. async Task<int> GetResultsAsync(){ return 5;}var r = await GetResultsAsync();
  37. 37. Naming conventions• By convention, the suffix "Async" is added• Async methods that return void are discouraged• Exceptions to the naming convention (e.g. event handlers)
  38. 38. ?
  39. 39. Valdis IljuconoksTechnical Fellow, Software ArchitectMicrosoft MVP Geta AS, Viiar Consulting valdis.iljuconoks@dotnet.lv http://dotnet.lv/blogs/vi @tech_fellow
  40. 40. www.dotnet.lv

×