You are on page 1of 12

Async Concepts

Agenda
• What does asynchrony mean?
• Reason for asynchrony.
• Task
• Async-await
• SynchronizationContext
• Best practices
Synchronous vs Asynchronous
Reason for asynchrony
• Responsiveness
• Scalability
Task
• Represents an asynchronous operation
• Stored on heap

• Also can be thought of as future/promises.


Issues with task usage
Difficult to write async programs:
Async-await
• No more call-backs
• But it is present behind the scenes.

await Awaitables
Message Loop/pump
• It fetches message from the message queue and dispatches it.
SynchronizationContext
• Abstraction over the place where you are running
• Represents a target for work

• Threads typically has a synchronization context

Post()
WinRTSynchronizationContext – CoreDispatcher.RunAsync()
UnitySynchronizationContext

Not all SynchronizationContext represents a single thread.


Async await - Best practices
• async void should be avoided
• Use configureAwait(false) in case if you don’t want to comeback to
the calling original thread
• Understand IO Bound vs CPU bound operation.
Thank You

You might also like