All about asynchronous programming from .NET starting from initial framework to latest version. We will be looking into almost all features from .NET which are related to Asynchronous Programming. This seminar will cover up evolution of asynchronous programming and slowly moving to Task.
6. Thread and ThreadPool
Basic building block for async programming.
Parameterize thread, came with .NET 2.0
Image source:http://johnpaulmorabito.blogspot.in/
7. APM and EAP
APM depends upon Begin and End methods.
Callbacks are dependent on IAsyncResult.
EAP came with .NET 2.0 which automatically
handles synchronization context.
BackgroundWorker is an example of EAP based
programming.
EAP can be seen while adding web reference
which automatically creates with proxies classes.
9. Task
A task is an abstraction of unit of work to run
asynchronously.
Ways to execute: new Task(Speak).Start(),
Task.Factory.StartNew(Speak),
Task.Run(Speak)
Use FromAsync when an API has
BeginXXX/EndXXX.
Task can be canceled through
CancellationToken and checked with
ThrowIfCancellationRequested.
IProgress<T> came with 4.5 which can be
used to show status
10. Task error handling
Task are completed with following state: Ran to
Completion, Canceled and Faulted.
Task uses AggregateException to wrap up any
other exception occurs which can be found under
inner exception.
AggregateException comes with Flatten method to
check all exceptions.
AggregateException also comes with Handle
method which accepts predicate to handle errors.
ThrowUnobservedTaskExceptions to configure
to shallow exception.
14. Task Relationships...
ContinueWhenXXX can be used to chain up
tasks with TaskContinuationOptions enum for
various conditions.
TaskCreationOptions.AttachedToParent is
used to create child tasks.
Creating child task will reflect exception in parent
task if exception occurs.
Task.Run uses
TaskCreationOptions.DenyChildAttach by
default which will act as nested task.