The document discusses asynchronous programming in C#, covering its definition, various programming models (APM, EAP, Task), and error handling techniques. It outlines the benefits of asynchronous capabilities in improving performance and provides resources for further learning. The presenter, Vikash Kumar from Mindfire Solutions, shares his expertise and contact information for audience engagement.
Introduction to session and presenter credentials, highlights on expertise in C# and related technologies.
Coverage of topics including asynchronous concepts, programming models, and options like APM, EAP, and Task.
Definition of asynchronous programming - performing multiple tasks simultaneously, historical context and different programming options.
Threads and ThreadPool serve as the basic building blocks for async programming introduced in .NET 2.0.
Asynchronous Programming Model (APM) utilizes Begin/End methods and the Event-Based Asynchronous Pattern (EAP) employs BackgroundWorker for synchronization.
Definition and execution of tasks, error handling via AggregateException, and state management of tasks.
Managing task relationships, chaining tasks, child tasks creation, and exception management between parent and child tasks.
Concluding remarks and question/answer session, with references for further reading.
Presentation closes with social media and contact information for Mindfire Solutions.
Thread and ThreadPool
Basicbuilding block for async programming.
Parameterize thread, came with .NET 2.0
Image source:http://johnpaulmorabito.blogspot.in/
7.
APM and EAP
APMdepends 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.
Task
A task isan 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
Taskare 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.
Task Relationships...
ContinueWhenXXX canbe 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.